Terraform

Download & Install Terraform on Windows, MacOS, Linux

How to download and install Terraform - tutorial

Developed by Hashicorp, Terraform is a powerful open-source Infrastructure as Code (IaC) tool that facilitates infrastructure management and creation on-premises and in the cloud. However, without proper guidance, beginners may find installing Terraform challenging.

In this guide, we show you how to install Terraform on Windows, Linux, or macOS:

Prerequisites

Before you start the installation process, there are some prerequisites which you will need to fulfill:

  • A Windows PC if you are installing on Windows
  • A Linux system (virtual or local) if you are installing on Linux (in this post, I am using Ubuntu 20.04 to demonstrate the steps)
  • Some basic CLI knowledge

In this post, I will be covering the installation steps for Terraform on three different operating systems. You can follow the steps based on the system you are using. These are the high level topics I will be covering in this post: 

  • Installing Terraform on Windows
  • Installing Terraform on Linux (Ubuntu) using Package repository
  • Installing Terraform on Linux using Zip archive file
  • Installing Terraform on macOS

How to Install Terraform on Windows

If you are installing Terraform on Windows, you will need to download the appropriate Terraform package from the Terraform download page, unpack it, and execute it using the CLI. Follow the steps below to make sure you install it correctly:

Download the installation file

1. Navigate to the Terraform download page (https://www.terraform.io/downloads.html). It should list out Terraform downloads for various platforms. Navigate to the Windows section and download the respective version. For this example I am downloading V1.1.0.

downloading V1.1.0 from Terraform downloads on Windows

2. It will download a zip file. Create a folder on the C drive as C:/terraform. Download the zip file in this folder. Unzip the file to extract the .exe file.

C:/terraform

Update Path Environment Variable

1. Next open the Start menu and search for Environment variables. Open the Environment variables settings page.

Update Path Environment Variable

2. On the Environment variables edit page, open the Path variable as shown below:

Edit environment variables

3. On the opened Path pop up, click New and add the Terraform download folder. This is the folder where the zip file was downloaded and unzipped (C:/terraform).

add the Terraform download folder

4. Click OK on the above window to save the Path variable addition. If needed, restart your system to apply the variable changes.

5. Open a Command prompt and run this command to verify Terraform is installed successfully:

verify if Terraform is installed successfully

Verify if the Correct Version of Terraform is Installed

Just like below:

correct version of Terraform

How to Install Terraform on Linux

If you are installing Terraform on Linux, you have two options: The most popular approach is to use the Terraform zip with the executable file you can uncompress in any location on your Linux system. Ensure the folder containing the executable file is in the PATH to access it from everywhere. Alternatively, you can use the HashiCorp repository.

Installation Using Package Repositories on Linux (Ubuntu)

First, I will go through the steps to install Terraform using the Linux package repository. Follow these steps for Ubuntu. For other Linux versions steps are similar and will depend on the specific package repositories. Log in to the system and run these steps as root for sudo access:

1. Make sure the system is up-to-date and install these packages which are needed for further steps:

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl

2. Next add the Hashicorp GPG key needed by the repository:

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -

3. Then, add the official repository for HashiCorp for Linux:

sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

4. Now that we have added the repo to the list, let’s update to add the relevant repository content:

sudo apt-get update

5. Once update, run this command to install Terraform:

sudo apt-get install terraform

That should complete the installation. To verify the installation, run this and verify the output:

verify the installation

To verify the version installed, run: terraform –version

correct version of Terraform

Install Using Package repositories on Linux

Next, we will see the method for installing Terraform using the downloaded zip file. Log in to the system and run these commands as root:  

1. Before starting the installation, get the download link from the Terraform website. Navigate to https://www.terraform.io/downloads.html and move to the specific OS version. Here we are looking for Linux:

download link for Linux from the Terraform site

2. Copy the link for the respective download:

Copy the link for the Linux download

3. Now, log in to the Ubuntu system. Make sure Wget and Unzip are installed. If not, install the same:

sudo apt-get install wget unzip

4. Download the Terraform zip file by running the following command. Put the URL copied earlier in the command for download:

wget
wget https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_linux_amd64.zip

5. The zip file should download:

The downloaded zip file

6. Unzip the zip file in the current folder:

unzip terraform_1.1.0_linux_amd64.zip
unzip terraform_1.1.0_linux_amd64.zip

7. The Terraform executable should get unzipped in the current folder:

terraform executable

8. Move the Terraform executable file to /usr/bin folder:

sudo mv terraform /usr/local/bin/

9. That should complete the Terraform installation. Verify the installation by verifying the version:

Verify the installation on Linux

How to Install Terraform on macOS

Install Terraform on macOS by downloading the Teffaform binary zip from Hashicorp, unzipping it and copying the binary to a place in the path.

1. Log in to the system and create a folder for the Terraform executable:

sudo mkdir -p /opt/terraform

2. Navigate to the new folder:

cd /opt/terraform

3. From the Terraform downloads website, copy the macOS Terraform zip file download link:

copy the Mac OS terraform zip file download link

4. Download the zip file in the previously created folder:

sudo curl -O <copied_url>

5. Unzip the Terraform files in the current folder:

sudo unzip <zip_file_name>

The unzipped files will be in the current folder.

6. Add Terraform to the PATH. Navigate to the home folder and execute this command to open and edit the bash profile:

sudo vi ~/.bash_profile

Add these two lines on the opened file:

PATH="/opt/terraform:${PATH}"
export PATH

7. Execute the file for the path changes to get into effect:

source ~/.bash_profile

8. Now that Terraform is installed, verify the Terraform version by running

terraform –version

This should show the Terraform version, which is installed in the system.

That completes your installation of Terraform on Mac OS.

Next step? Import existing infrastructure into Terraform. See more here: How to Import Existing Infrastructure into Terraform (Tutorial with Examples)

Key Points

Terraform allows you to convert a whole cloud infrastructure to config or code files. These files can be used to spin up the entire infrastructure quickly and easily. It is an open source tool by Hashicorp. Anyone can use it to manage a cloud infrastructure on any of the cloud providers. 

In this post, we went through the steps to install Terraform on Windows, Linux, as well as macOS. I hope this helps you with your installations. And if you’re interested in how to upgrade Terraform to the latest version, see: Upgrading Terraform to the Latest Version.

Note: New versions of Terraform are placed under the BUSL license, but everything created before version 1.5.x stays open-source. OpenTofu is an open-source version of Terraform that expands on Terraform’s existing concepts and offerings. It is a viable alternative to HashiCorp’s Terraform, being forked from Terraform version 1.5.6.

If you want more help managing your Terraform state file, building more complex workflows based on Terraform,  creating self-service infrastructure, and many more great features right out of the box check out Spacelift. Get started on your journey by creating a trial account.

Terraform Management Made Easy

Spacelift effectively manages Terraform state, more complex workflows, supports policy as code, programmatic configuration, context sharing, drift detection, resource visualization and includes many more features.

Start free trial

The Practitioner’s Guide to Scaling Infrastructure as Code

Transform your IaC management to scale

securely, efficiently, and productively

into the future.

ebook global banner
Share your data and download the guide