Skip to main content

Complete Guide for Installing Terraform on Windows, macOS, and Linux

This guide will cover the steps required to install Terraform on different operating systems: Windows, macOS, and Linux. Terraform is an Infrastructure as Code (IaC) tool that allows you to provision and manage infrastructure resources on various cloud platforms.

Installation on Windows​

Step 1: Download Terraform​

  1. Visit the Terraform Downloads Page.
  2. Scroll down to the Windows section.
  3. Download the appropriate version of Terraform for your system architecture (32-bit or 64-bit).

Step 2: Extract the Downloaded File​

  1. Extract the .zip file you downloaded using a tool like WinRAR or 7-Zip.
  2. Place the terraform.exe binary into a folder of your choice. For simplicity, place it in a folder like C:\Terraform.

Step 3: Add Terraform to System Path​

To use Terraform from the command line, you need to add it to your system's PATH.

  1. Right-click on This PC and choose Properties.
  2. Select Advanced system settings.
  3. In the System Properties window, click Environment Variables.
  4. Under System Variables, find and select the Path variable, then click Edit.
  5. In the Edit Environment Variable window, click New and add the path where you placed terraform.exe (e.g., C:\Terraform).
  6. Click OK to close all the windows.

Step 4: Verify Installation​

  1. Open a new Command Prompt or PowerShell window.

  2. Run the following command to verify the installation:

bash
terraform -v

This should display the Terraform version if it was installed correctly.

Installation on macOS​

Step 1: Install Terraform Using Homebrew​

Homebrew is a package manager for macOS that simplifies the installation of software.

  1. Open Terminal.

  2. Run the following command to install Homebrew if it is not installed:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Once Homebrew is installed, use it to install Terraform:
bash
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Step 2: Verify Installation​

  1. After installation, verify Terraform by running:
bash
terraform -v

This will display the installed version of Terraform.

Step 3: Update Terraform​

To update Terraform in the future, run:

bash
brew upgrade hashicorp/tap/terraform

Installation on Linux​

Step 1: Download Terraform​

  1. Visit the Terraform Downloads Page.
  2. Scroll down to the Linux section.
  3. Download the appropriate version for your Linux architecture (most systems will use the 64-bit option).

Step 2: Extract and Move the Terraform Binary​

  1. Open your terminal and navigate to the directory where the Terraform package was downloaded:
bash
cd ~/Downloads
  1. Unzip the file (replace <version> with the actual version downloaded):
bash
unzip terraform_<version>_linux_amd64.zip
  1. Move the Terraform binary to /usr/local/bin to make it globally accessible:
bash
sudo mv terraform /usr/local/bin/

Step 3: Verify Installation​

  1. To check if Terraform is installed correctly, run:
bash
terraform -v

This should display the installed version of Terraform.

Step 4: Install Terraform via Package Manager (Optional)​

Some Linux distributions have HashiCorp's official repository that allows installing Terraform via the package manager.

For Ubuntu/Debian:
  1. Add HashiCorp’s GPG key:
bash
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  1. Add the official repository to your system:
bash
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  1. Update and install Terraform:
bash
sudo apt update
sudo apt install terraform
For CentOS/RHEL:
  1. Add the HashiCorp repo:
bash
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
  1. Install Terraform:
bash
sudo yum install terraform

Step 5: Verify Installation​

  1. Run the following command to verify that Terraform is installed:
bash
terraform -v

4. Verifying and Using Terraform​

Once Terraform is installed on any platform (Windows, macOS, or Linux), you can verify the installation and check the version by running:

bash
terraform -v

This command will display the version of Terraform installed. You can now begin using Terraform by creating a main.tf configuration file and running Terraform commands like terraform init, terraform plan, and terraform apply to deploy infrastructure.

Updating Terraform​

To update Terraform, follow these steps:

  • Windows: Download the latest binary from the official Terraform website, replace the old binary in your folder, and restart your terminal.
  • macOS: Run brew upgrade hashicorp/tap/terraform to update via Homebrew.
  • Linux: Depending on the installation method, either download the latest binary and repeat the installation steps or use the package manager to update.

Transform Your Business with Expert DevOps Solutions

Our tailored DevOps consulting services help streamline your processes, accelerate delivery, and ensure scalability.

Conclusion​

Terraform is now installed on your system. With Terraform, you can define your infrastructure as code, allowing for consistent and repeatable infrastructure provisioning across multiple environments. Start by writing your infrastructure in Terraform configuration files and using commands like terraform init, terraform plan, and terraform apply to deploy resources to the cloud.