How to Install Terraform on Windows, Linux, and MacOS

November 23, 2022

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 disparate 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 sudo privileges.
  • wget and unzip installed for Linux and curl for macOS.
  • Access to the terminal/command-line tool.

How to Install Terraform on Windows

Installing Terraform on Windows requires you to download the correct Terraform package, unpack, 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. Browse to the Download Terraform page.

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

Windows tab to download Terraform

3. Choose the binary to download. Select 386 for 32-bit systems or AMD64 for 64-bit systems. Choose the download location for the zip file if the download does not start automatically.

4. Unzip the downloaded file. For example, use the C:\terraform path. Remember this 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. The System Properties window opens.  

2. Click the Environment Variables... button.

Windows Environment Variables button

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. Click Edit once you select a Path.

Select the Path variable in the System 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 on 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. Enter the command to check the Terraform version: terraform -version

terraform -version
Command Prompt Windows checking the Terraform version

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 your system. The other method is using the HashiCorp repository for your Linux distribution.

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 are the same for 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 to download the file:

wget https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_linux_amd64.zip
wget tool downloads the terraform file on Linux

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

echo $PATH
echo $PATH output Linux

We will use /usr/local/bin.

6. Unzip the file to the directory you chose. 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.3.5, enter:

sudo unzip terraform_1.3.5_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 list command. For example:

ls -l /usr/local/bin

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

terraform -version

The output shows the Terraform version you installed.

Install Terraform on Linux Using Package Repository

Follow the steps for your Linux distribution to install Terraform from the official HashiCorp repository. The repository contains other HashiCorp packages that are not related to Terraform.

Install Terraform on CentOS/RHEL

To install Terraform from the HashiCorp repository on a CentOS system:

1. Install the yum-utils tools.

sudo yum install -y yum-utils
Installing the yum-utils tools on CentOS

Note: For DNF-based distributions, use sudo dnf install -y dnf-plugins-core.

2. Add the HashiCorp repository:

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

3. Install Terraform using the yum package manager:

sudo yum -y install terraform
Terraform installation completed with version in the output.

The output shows that Terraform is installed. You can double-check by running the terraform -version command to see the installed Terraform version.

Install Terraform on Ubuntu/Debian

To install Terraform from the HashiCorp repository on an Ubuntu and Debian system:

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
Terraform 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 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.

terraform -version command output on Ubuntu.

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, we'll 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. In our case, it is ARM64.

The Download Terraform page for macOS.

4. Use curl to download the file:

curl https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_darwin_arm64.zip
curl Terraform download command

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

echo $PATH
echo $PATH on macOS

In our case, /usr/local/bin.

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.3.5, enter:

sudo unzip terraform_1.3.5_darwin_arm64.zip -d /usr/local/bin
unzip Terraform on macos via Terminal

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

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

ls -l /usr/local/bin

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

terraform -version
Check Terraform version on macOS using the terminal.
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 by running:

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

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

Conclusion

The steps in this guide showed you how to install Terraform on all major operating systems and how to verify the installation was successful.

Learn 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