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.
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.
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.
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.
4. Click New in the edit window and enter the 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
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.
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
5. Run the command below to find a user directory in $PATH to put the Terraform binary in it:
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
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
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
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
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.
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
5. Find a user directory in &PATH to put the Terraform binary in it:
echo $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
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
7. Confirm the installation is successful by running a terraform command:
terraform -version
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
2. Install Terraform from the new repository by running:
brew install hashicorp/tap/terraform
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.