Installation of Terraform in Ubuntu : Step by Step Procedure

Terraform is distributed as a tarball on Github. Check the latest release on Terraform releases page before downloading below.There are two methods from which we can install terraform on Ubuntu22.04|20.04 |18.04.

Method 1: Install Terraform from APT repository

Terraform team offers package repositories for Debian based Linux, which allow you to install Terraform using the apt package management tool or any other APT frontend.

First, install repository addition dependencies:

sudo apt update
sudo apt install  software-properties-common gnupg2 curl

Now import repository GPG key

curl | gpg --dearmor > hashicorp.gpg
sudo install -o root -g root -m 644 hashicorp.gpg /etc/apt/trusted.gpg.d/

With the key imported now add Hashicorp repository to your Ubuntu system:

sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] $(lsb_release -cs) main"

Expected execution output:

Repository: 'deb [arch=amd64] jammy main'
Archive for codename: jammy components: main
More info:
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_apt_releases_hashicorp_com-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_apt_releases_hashicorp_com-jammy.list
Hit:1 jammy InRelease
Hit:2 jammy-updates InRelease
Hit:3 jammy-backports InRelease
Hit:4 jammy-security InRelease
Get:5 jammy InRelease [12.0 kB]
Get:6 jammy/main amd64 Packages [74.4 kB]
Fetched 86.4 kB in 1s (84.6 kB/s)
Reading package lists... Done

Now install terraform on your Ubuntu Linux system:

sudo apt install terraform

Check the version of terraform installed on your system

$ terraform --version
Terraform v1.3.7
on linux_amd64

Method 2: Install Terraform Manually

The primary distribution packages for Terraform are .zip archives containing single executable files that you can extract anywhere on your system

Ensure wget and unzip packages are installed on your Ubuntu system:

sudo apt install wget unzip -y

Then download the latest terraform archive.

TER_VER=`curl -s | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`

Once downloaded, extract the archive:

$ unzip terraform_${TER_VER}
  inflating: terraform

This will create a terraform binary file on your working directory. Move this file to the directory/usr/local/bin.

sudo mv terraform /usr/local/bin/

This will make the tool accessible to all user accounts.

$ which terraform

Confirm the version installed

$ terraform version
Terraform v1.3.7
on linux_amd64

Leave a Comment

MFH IT Solutions (Regd No -LIN : AP-03-46-003-03147775)

Consultation & project support organization.


MFH IT Solutions (Regd)
NAD Kotha Road, Opp Bashyam School, Butchurajupalem, Jaya Prakash Nagar Visakhapatnam, Andhra Pradesh – 530027