How to Install Terraform on Ubuntu 20.04
Hi everyone, in this article, we will be exploring two different ways of installing Terraform on Ubuntu 20.04 and an additional method for automation using a script. The good thing about exploring these methods is that they follow the documented processes on Terraform documentation and can be applied to other Ubuntu versions.
Installling Terraform on Ubuntu 20.04
As mentioned earlier in the introduction section, Terraform has documented two methods of installing it which are:
Installation as a binary package that falls in the manual installation category.
Installation with package managers.
Then, I will add a bonus method of using a bash script that will help you install Terraform in under two minutes with minimal typing.
Steps for Method 1 (Manual Installation):
On this install Terraform's official page, click on the
Manual installationtab then, thepre-compiled binaryoption.The
pre-compiled binaryoption gives you a set of instructions, one of which you are to click on theappropriate packagelink. The link takes you to a page to get the package for different operating systems as a zip archive.
Since we are installing on an Ubuntu 20.04 machine, click on the
Linuxtab. Then, click on the right architecture version for your Linux system. In this case, I am going with theAMD64version. So, right-click on theDownloadoption and copy the link to the address.
On the Ubuntu terminal, use this command to download the zipped folder to your system.
wget -c https://releases.hashicorp.com/terraform/1.5.1/terraform_1.5.1_linux_amd64.zipUse the
lscommand to confirm the download and unzip the file with theunzipcommand. However, you will likely have to install the unzip package first with the package manager.sudo apt install unzip -y unzip terraform_1.5.1_linux_amd64.zipTo confirm that the previous step was executed, the
lscommand should giveterraformas one of the directories. After this, use theecho $PATHcommand to check for available paths on your Linux machine and move the terraform folder into one of them. As directed by the documentation, we will move it to the/usr/local/binfolder.echo $PATH sudo mv terraform /usr/local/binTo test our installation, you can use any of these commands:
terraform -help,terraform -version, e.t.c.
Steps for Method 2 (Package Manager):
On the same Install Terraform page, click on the
Linuxtab to access the Linux/Debian instructions. Then, copy and paste the code lines one after the other on your Ubuntu terminal.sudo apt-get update && sudo apt-get install -y gnupg software-properties-commonThis first command helps to update the apt package manager repository and thereafter, install some other packages required for our installation.
The next step is to install the Hashicorp GPG key and add the repository to your system:
wget -O- https://apt.releases.hashicorp.com/gpg | \ gpg --dearmor | \ sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg 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.listThe next step is to update the apt package manager and install Terraform.
sudo apt update sudo apt-get install terraform -yTo test the installation, open a new terminal session and use any of these commands:
terraform -help,terraform -version, e.t.c.
Bonus Method:
Finally, to make the second method even faster, I have a GitHub repository where you can access a script I have written to install Terraform. All you have to do is Clone the repository with:
git clone https://github.com/Adephumie/bash-scripts-for-automation.git
Then, change into the terraform-installation directory, and make the code executable by running this code line:
sudo chmod +x terraform.sh
The next thing is to run the code to install Terraform on the Ubuntu machine as follows.
./terraform.sh
Conclusion
And now, you have the two methods of installing Terraform on Ubuntu 20.04 and the bonus method using a bash script to install Terraform. Thank you.



