How to Install Terraform on Windows, Linux, Mac
When I started learning Terraform, the first thing I struggled with was getting proper instructions on how to install Terraform on my system or any cloud server which I was using. There are many resources available online that guide you through the installation steps, and of course Terraform docs also have a very good installation guide.
In this guide you will find all the necessary steps in one place regardless of whether you are installing 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
1. How to Install Terraform on Windows
-
Download the installation file
Step 1: Browse to the Download Terraform page.
Step 2: Select the Windows tab under the Operating System heading. The latest version is preselected.
Step 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.
Step 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.
-
Update Path Environment Variable
Step 1: Next open the Start menu and search for Environment variables. Open the Environment variables settings page.
Step 2: On the Environment variables edit page, open the Path variable as shown below:
Step 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).
Step 4: Click OK on the above window to save the Path variable addition. If needed, restart your system to apply the variable changes
Step 5: Open a Command prompt and run this command to verify Terraform is installed successfully:
-
Verify if the Correct Version of Terraform is Installed
Just like below:
2.How to Install Terraform on Linux
Here I am taking an example of installing on Ubuntu 20.04 to demonstrate the Linux installation. There are two paths to install on Linux. We’ll go through each path below.
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:
Step 1. Make sure the system is up-to-date and install these packages which are needed for further steps:
sudo apt update && sudo apt install -y gnupg software-properties-common curl
Step 2: Next add the Hashicorp GPG key needed by the repository:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
Step 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"
Step 4. Now that we have added the repo to the list, let’s update to add the relevant repository content:
sudo apt update
Step 5: Once update, run this command to install Terraform:
sudo apt install terraform
That should complete the installation.To verify the version installed, run: terraform –version
3.How to Install Terraform on macOS
To install terraform on macOS using the official HashiCorp repository:
Step 1: Add the Terraform repository:
brew tap hashicorp/tap
Step 2: Install Terraform from the new repository by running:
brew install hashicorp/tap/terraform
Step 3. Run the Terraform version command to check 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 the installation was successful.
Good Luck!