How to Install Terraform on Windows, Linux, and macOS

August 8, 2024

HashiCorp Terraform is an open-source Infrastructure as Code (IaC) software that facilitates infrastructure management and creation. The tool is extremely popular with DevOps teams, as it allows them to define the resources via config files to automate infrastructure provisioning for different providers.

This guide will show you how to install Terraform on Windows, Linux, and macOS, with examples.

How to install Terraform on Windows, Linux, and macOS with examples.

Prerequisites

  • A user account with admin or root privileges.
  • wget and unzip installed for Linux and curl for macOS.
  • Access to the terminal/command line.

How to Install Terraform on Windows

Installing Terraform on Windows requires you to download the correct Terraform package, unpack it, and execute it via the CLI. Follow the instructions below to ensure you do not miss any steps.

Download Terraform File for Windows

To find the latest version of Terraform for Windows:

1. Navigate to the Install Terraform page.

2. Select the Windows tab under the Operating System heading. The latest version is preselected.

Download Terraform File for Windows

3. Choose the binary to download. Select 386 for 32-bit systems or AMD64 for 64-bit systems. If the download does not start automatically, choose the download location for the zip file and click Save.

4. Unzip the downloaded file. The best practice is to use a simple extraction path. For example, C:\terraform. Remember the location so you can add the path to the environment variables.

Add Terraform Path to System Environment Variables

To add the Terraform executable to the system's global path:

1. Open the start menu, start typing environment, and click Edit system environment variables result. The System Properties window opens.  

2. Click the Environment Variables... button.

Windows Environment Variables settings.

3. Select the Path variable in the System variables section to add Terraform for all accounts. Alternatively, select Path in the User variables section to add Terraform for the currently logged-in user only.

Double-click the variable to edit it.

Editing the Path variable in the System and User variables.

4. Click New in the edit window and enter the location of the Terraform folder:

Enter the new location of the Terraform folder.

5. Click OK in all windows to apply the changes.

Verify Windows Terraform Installation

To check the Terraform global path configuration:

1. Open a new Command Prompt window.

2. Run the command below to check the Terraform version:

terraform -version
Checking the Terraform version in Windows Command Prompt.

The output shows the Terraform version you downloaded and installed on your Windows machine.

How to Install Terraform on Linux

There are two methods to install Terraform on Linux. The primary method is using the Terraform zip that contains the executable you can unpack anywhere on the machine. The other method is to add the HashiCorp repository and install Terraform using your package manager.

Install Terraform on Linux Using Zip Archive

Follow the steps below to install Terraform on a Linux system using the downloaded zip file. The instructions apply to all Linux distributions.

1. Browse to the Download Terraform page.

2. Select the Linux tab under the Operating System heading. The latest version is preselected.

3. Scroll down and right-click the Download button for your system's architecture. In our case, it is AMD64.

Download Terraform for Linux.

4. Use the wget tool and the link you previously copied to download the file:

wget https://releases.hashicorp.com/terraform/1.9.2/terraform_1.9.2_linux_amd64.zip
Download terraform file on Linux using wget.

5. Run the command below to find a user directory in $PATH to put the Terraform binary in it:

echo $PATH
An example output of echo $PATH.

We will place the Terraform executable file in /usr/local/bin.

6. Unzip the file to the directory you chose in the previous step. Use the full file name with the extension when extracting the archive. Make sure to use the correct name for your architecture and the version you downloaded. For example, for version 1.9.2, run:

sudo unzip terraform_1.9.2_linux_amd64.zip -d /usr/local/bin
Extracting the Terraform archive on Linux.

The output shows the path where the extracted Terraform file is located.

To verify if the Terraform directory is in the selected location, use the ls command. For example:

ls -l /usr/local/bin

7. Verify the installation by running a terraform command. For example, check the version with:

terraform -version
Check Terraform program version on Linux.

The output shows the Terraform version you installed.

Install Terraform on Linux Using Package Repository

The steps below show how to install Terraform from the official HashiCorp repository. The repository contains other HashiCorp packages that are not related to Terraform. For this tutorial, we will use Ubuntu.

1. Use wget and download the signing key to a new keyring:

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
Downloading the signing key to a new keyring on Ubuntu.

2. Add the HashiCorp repository and find the distribution release codename for your OS:

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

3. Update the system package information:

sudo apt update

4. Use apt to install Terraform from the new repository.

sudo apt install terraform
Install Terraform from the new repository using apt on Ubuntu.

To verify the latest Terraform version is installed, run the terraform -version command.

How to Install Terraform on macOS

Installing Terraform on macOS is possible via the zipped file with the Terraform binary and via the official HashiCorp repository. The repository contains other non-Terraform HashiCorp products you can install later.

Install Terraform on macOS Using Zip Archive

The steps to install Terraform on macOS using the downloaded zip archive are similar to the instructions for Linux systems. Instead of wget, use curl on macOS.

1. Browse to the Download Terraform page.

2. Select the macOS tab under the Operating System heading. The latest version is preselected.

3. Right-click the Download button for your system's architecture and copy the download link. In our case, it is ARM64.

Download Terraform for macOS.

4. Use curl to download the file from the link you copied in the previous step:

curl https://releases.hashicorp.com/terraform/1.9.2/terraform_1.9.2_darwin_arm64.zip -O
Download installation file with curl.

5. Find a user directory in &PATH to put the Terraform binary in it:

echo $PATH
Find a user directory in $PATH.

In our case, we will use the /usr/local/bin directory.

6. Use the full file name with the extension when extracting the archive. Make sure to use the correct name for your architecture and the version you downloaded. For version 1.9.2, enter:

sudo unzip terraform_1.9.2_darwin_arm64.zip -d /usr/local/bin
Unzip Terraform on macOS via the Terminal.

The output shows the path where the extracted Terraform file is located.

Use the ls command to verify if the Terraform directory is in the selected location. For example:

ls -l /usr/local/bin
Checking directory contents with ls command.

7. Confirm the installation is successful by running a terraform command:

terraform -version
Check Terraform version on macOS using the terminal.

The output shows the Terraform version you installed.

Install Terraform on macOS from Repository

To install terraform on macOS using the official HashiCorp repository:

1. Add the Terraform repository:

brew tap hashicorp/tap
Adding the Terraform repository on macOS.

2. Install Terraform from the new repository by running:

brew install hashicorp/tap/terraform
Installing Terraform from the new repository on macOS.

3. Run the Terraform version command to check the installed version.

terraform -version

Conclusion

This guide explained how to install Terraform on all major operating systems and how to verify that the installation was successful. Terraform is useful because it allows you to provision infrastructure with consistent, repeatable processes, ensuring scalable and reliable environments.

Next, learn the difference between Terraform and Kubernetes, or see how to provision a Terraform infrastructure and utilize the full potential of this tool.

Was this article helpful?
YesNo
Goran Jevtic
Goran combines his leadership skills and passion for research, writing, and technology as a Technical Writing Team Lead at phoenixNAP. Working with multiple departments and on various projects, he has developed an extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
How to Provision Infrastructure with Terraform
August 25, 2022

Terraform is a tool that uses the declarative approach to configuration, allowing users to define and provision infrastructure in a safe and efficient way.
Read more
Terraform vs Kubernetes: What Are the Differences
November 9, 2023

This article provides an overview of two popular automation choices, Terraform and Kubernetes, and shows popular use cases for both tools.
Read more
How to Install Terraform on CentOS
July 2, 2019

Terraform is a tool that creates a single provisioned interface for several different cloud-based services. This guide will help you install Terraform on CentOS.
Read more
Server Automation Guide
November 10, 2022

This guide discusses server automation and the role server automation plays in infrastructure management procedures.
Read more