Install terraform on Ubuntu 20.04, CentOS 8, MacOS, Windows 10, Fedora 33, Red hat 8 and Solaris 11



In this guide, we will focus on Installation of Terraform on a various operating system such as Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8, and Solaris.

  1. Install Terraform on Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8 or Solaris
  2. Install Terraform on Windows 10
  3. Install Terraform on MacOS

Later we are also going to see How to Upgrade Terraform using tfenv?

  1. Upgrade Terraform using tfenv
  2. Upgrade Terraform to Specific version using tfenv
  3. Uninstall the Terraform




1. Installing Terraform on Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8, or Solaris

The instructions and command for installing Terraform on Ubuntu 20.04 OR CentOS 8 OR Fedora 33|32|31 is almost same. You only need to pay attention to which version of the host OS you are choosing. Is it 32 bit or 64 Bit?

1.1 Install the Terraform using official Package distribution

Ubuntu

  1. Update apt-get package manager
1sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl 
  1. Install official hashicorp repository
1curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
1sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 
  1. Install terraform
1sudo apt-get update && sudo apt-get install terraform  

Centos

  1. Install yum-config-manager
1sudo yum install -y yum-utils 
  1. Add official HashiCorp Linux repository
1sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
  1. Install
1sudo yum -y install terraform

Fedora

  1. Install yum-config-manager
1sudo dnf install -y dnf-plugins-core
  1. Add official HashiCorp Linux repository
1sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo 
  1. Install terraform
1sudo dnf -y install terraform 


1.2 The manual way to install Terraform

To install terraform manually you first need to download the terraform zip file from the hasicorp official website and to download zip file on the linux machine you need wget utility.

In case if you do not have wget then use the following command to install it -

  1. Ubuntu 20.04 | 18.10 | 18.04 :
1sudo apt-get install wget unzip 
  1. CentOS 8 | 7 :
1sudo yum install wget unzip
  1. Fedora 33 | 32 | 31 :
1bash sudo dnf install wget 

Download the terraform.zip file

1. Goto Terrafrom.io

2. Click on Download CLI and for Ubuntu

Terraform.io for terraform installation on Ubuntu

3. On the download page you will find an option Linux, so based on your operating system architecture choose a suitable option (32-bit | 64-bit | Arm | Arm64). I choose the 64 bit

Download terrafrom for 64 bit Ubuntu

4. Right-click on 64-Bit option then click on Copy Link Location (We need to copy the download link)

Copy Link location for downloading the terraform

5. Open Terminal and use the wget command followed by the link which you copied in the previous step.

1wget  https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip
  1. After successful download you will see a ZIP file inside your directory

terraform ZIP



Unzip and move the file to '/usr/local/bin'

1. Unzip the terraform ZIP file

1unzip terraform_0.14.7_linux_amd64.zip

2. After the UNZIP you should see a file named terraform

3. Move the file terraform to /usr/local/bin

1sudo mv terraform /usr/local/bin/

Verify the Terraform installation on Ubuntu

You can confirm the installation by running the following command

1terrafrom -v 

It should return you with the version which you have installed. In my case, the version was - Terraform v0.14.7

1Terraform v0.14.7


2. Installing Terraform on Windows 10

Download the terraform.zip file

1. Head over to Terrafrom.io and click on [Download CLI](https://www.terraform. io/downloads.html)

2. Scroll down the page and look for the Windows option. After that you need to select the version 32 Bit | 64 Bit. (In my case I had 64 Bit Windows 10, so I choose 64 Bit option for download)

Download Terraform 64 bit for Windows 10

3. Once you click on either 32 Bit or 64 Bit, it will download a ZIP file for you.


Move and Extract the Terraform ZIP file

1. let's move the ZIP file to some good location. In my case, I moved the file to C:\Terraform (You can move the ZIP file to any location of your choice but always remember the path onto which you are moving the file)

2. Extract the Terraform ZIP file (After the extraction it should have one file terraform.zip)

Path of terraform.exe after extracting it on windows 10


Add the Terraform directory PATH to Windows 10 environment variable

1. Copy the path of the folder where you placed terraform.exe (In my case the path was C:\Terraform)

2. Goto Start Menu and type in the Environment Variables in the search box and then click on Open

Update environment variable for terrform installation on windows 10

3. Once you open the environment variables window you need to click on Environment Variables (You can find it at the bottom of the window)

Open environment variables for installtion of terraform in windows 10

4. Goto -> System Variables then look for the system variable named Path

Edit PATH environment variable for installation of Terraform on Windows 10

5. Click on Edit and it should open another window. Click on new and past the path of your terraform directory

Add new Environment variable for terraform installation



Verify the Terraform installation on Windows 10

You can verify the installation by opening the command prompt and then typing the following command -

1terraform -v 

If you have successfully installed the terraform then it should return you with the version number.

Terraform version command on windows 10 command prompt


3. Installing Terraform on MacOS

Install the Terraform on MacOS using brew

This is one of my favorite ways to install any package on my macOS, but here are the steps for installing Terraform using HomeBrew

1. Use the following Homebrew command it will install the Terraform for you.

1brew install terraform
1==> Downloading https://homebrew.bintray.com/bottles/terraform-0.14.3.catalina.bot
2==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/1172ae8f9a7ac2bed83ca13
3######################################################################## 100.0%
4==> Pouring terraform-0.14.3.catalina.bottle.tar.gz
5🍺  /usr/local/Cellar/terraform/0.14.3: 6 files, 63.9MB 

Install Terraform manually on macOS

1. You can download the Terrafrom.io from [Download CLI](https://www.terraform. io/downloads.html)

2. Extract the downloaded ZIP file

3. Move the ZIP file using the following command

1sudo mv $HOME/Downloads/terraform /usr/local/bin/

Verify the Terraform installation on macOS

You can verify the Installation of Terraform on macOS by running the following command

1terraform -v

It should return you with the version which you have installed onto your macOS

1Terraform v0.14.3

4. Upgrade Terraform using tfenv

4.1 Install tfenv on Ubuntu 20.04 | CentOS 8 | Fedora 33 | Red hat 8 | Solaris 11

The installation of tfenv is pretty straight forward but you should at least know how to do git clone or you should be familiar with git.

1. Clone the tfenv repo

1git clone https://github.com/tfutils/tfenv.git ~/.tfenv 

2. Add ~/.tfenv/bin to your $PATH

1echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile 

3. Create symlink for ~/.tfenv/bin/*

1mkdir -p ~/.local/bin/ 
1. ~/.profile
1ln -s ~/.tfenv/bin/* ~/.local/bin
1which tfenv 

4.2 Verify the tfenv installation

You can use the following command to verify the installation of tfenv

1tfenv 

It should return you with version

 1tfenv 2.2.0
 2Usage: tfenv <command> [<options>]
 3
 4Commands:
 5   install       Install a specific version of Terraform
 6   use           Switch a version to use
 7   uninstall     Uninstall a specific version of Terraform
 8   list          List all installed versions
 9   list-remote   List all installable versions
10   version-name  Print current version
11   init          Update environment to use tfenv correctly.

4.3 List available version using $ tfenv list-remote

Before upgrading Terraform version, you should check which versions of Terraform are available.

Run the following command to check the available version

1tfenv list-remote

You will see the following output based on the latest available version -

 10.15.0-beta1
 20.15.0-alpha20210210
 30.15.0-alpha20210127
 40.15.0-alpha20210107
 50.14.7
 60.14.6
 70.14.5
 80.14.4
 90.14.3
100.14.2
110.14.1
120.14.0

4.4 Install the latest version of Terraform

There is the default latest command provided by tfenv which will install the latest version of Terraform onto your system

1tfenv install latest

5. Upgrade to a specific version of Terraform

If you really want to upgrade to a specific version of Terraform then always keep the correct version of Terraform handy with you. (At the time of writing this article the latest stable version of Terraform is 0.14.7)

1tfenv install 0.14.7

There is one more feature provided by the tfenv. If you want to upgrade to the latest version of some specific release for example you want the latest version from 0.14 release then you can do it by running -

1tfenv install latest:^0.14

5.1 Change terraform version (If you have already installed multiple versions of Terraform)

Let's say you have installed multiple version(0.14.7, 0.14.6, 0.14.5) of terraform and now you want to switch between the versions then use the following command to achieve that

1tfenv use 0.14.6

The above command will switch to terraform to version 0.14.6

But if you use only terraform use then it will switch the latest version of Terraform.

1 tfenv use

The above command will switch to version 0.14.7 because at the time of writing this article 0.14.7 is latest the version provided by terraform


6. Uninstall the Terraform

The uninstallation command of the Terraform is very simple -

1tfenv uninstall 0.14.7
1Uninstall Terraform v0.14.7
2Terraform v0.14.7 is successfully uninstalled 

Read More - Terragrunt -

  1. How to use Terragrunt?

Posts in this Series