How to Install Terraform on Windows, Linux, and MacOS

HashiCorp Terraform is an open source infrastructure-as-code (IaC) software that makes it easy to manage and build infrastructure. The tool is extremely popular with DevOps teams as it allows them to define resources through configuration files to automate infrastructure provisioning for disparate vendors.

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

Prerequisites

  • A user account with administrator 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, unzip it, and run it via the CLI. Follow the instructions below to make sure you don’t skip any steps.

Download Terraform file for

Windows

To find the latest version of Terraform for Windows:

1. Go to the Download 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. Choose the download location of the zip file if the download does not start automatically.

4. Unzip the downloaded file. For example, use the path C:\terraform. Remember this location so that you can add the path to the environment variables.

Add Terraform Path to System

Environment Variables

To add the Terraform executable to the system global path:

1. Open the start menu, start typing the environment, and click Edit System Environment Variables. The System Properties window opens.

Arabic numeral. Click 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 only for the currently logged in user. Click Edit once you select a path.

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

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

Verify your Windows Terraform installation

To verify the Terraform global path settings:

1. Open a new Command Prompt window.

2. Enter the command to check

the Terraform version: terraform -version terraform -version

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

. How to install Terraform on Linux There are two methods to

install Terraform

on Linux. The main method is to use the Terraform zip that contains the executable that you can unpack anywhere on your system. The other method is to use 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. Go 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 on the Download button for your system architecture. In our case, it’s AMD64.

4. Use wget

tool to download file: wget

https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_linux_amd64.zip 5. Find a user directory in &PATH to put the Terraform binary in it:

echo $PATH

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 file. Be sure to use the correct name for the architecture and version you downloaded. For example, for version 1.3.5, type:

sudo unzip terraform_1.3.5_linux_amd64.zip -d /usr/local/bin

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

.

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

ls -l /usr/local/bin

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

terraform -version

The output shows the version

of Terraform you installed. Install Terraform on Linux using the package repository Follow the steps to have your

Linux

distribution

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

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

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

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 keychain: 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 version codename for your operating system:

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

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

.

How to install

Terraform on MacOS The installation of Terraform

on MacOS is possible through the compressed file with the Terraform binary and through the official HashiCorp repository. The repository contains other non-Terraform HashiCorp products that you can install later.

Install Terraform on

MacOS using Zip

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

1. Go 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 the system architecture. In our case, it’s ARM64.

4. Use curl

to download the file: curl

https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_darwin_arm64.zip

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

echo $PATH

In our case, /usr/local/bin

.

6. Use the full file name with the extension when extracting the file. Be sure to use the correct name for the architecture and version you downloaded. For version 1.3.5, type:

sudo unzip terraform_1.3.5_darwin_arm64.zip -d /usr/local/bin

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

.

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

ls -l /usr/local/bin

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

-version <img src="https://phoenixnap.com/kb/wp-content/uploads/2022/11/check-terraform-version-macos.png" alt="Check the version of Terraform on macOS using the terminal.

” />
Check the version of Terraform on macOS using the terminal.

The output shows the version of Terraform that you installed.

Install Terraform on MacOS from

the 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 verify the installed version.

terraform -version

Conclusion

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

.

Learn how to provision a Terraform infrastructure and use the full potential of this tool.