How to install Terraform on Ubuntu 22.04?

Terraform is software like code software that allows the users to create. change, and also improve the infrastructure. The “Terraform” is called Infrastructure as Code (IaC), which represents any infrastructure in the code form. Usually, it is used by the DevOps teams to build and automate infrastructure tasks.

This post will demonstrate the installation of Ubuntu, and the content of this post is as follows:

How to Install Terraform on Ubuntu

This section enlists various steps to install Terraform on Ubuntu 22.04.

Step 1: Add the GPG Key

For the installation of Terraform, first add the gpg key of Terraform on Ubuntu using the command:

$ wget -O- https://apt.releases.hashicorp.com/gpg | \
    gpg --dearmor | \
    sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

Step 2: Validate the Authentication Process

After adding the GPG key, for security reasons, match the fingerprint with the code “E8A0 32E0 94D8 EB4E A189 D270 DA41 8C88 A321 9F7B” using the command:

$ gpg --no-default-keyring \
    --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
    --fingerprint

Step 3: Add the Repository

After matching the code, add the repository of Terraform using the command:

$ 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.list

Step 4: Update the Packages

Then update the packages of Ubuntu:

$ sudo apt update

Step 5: Install the Terraform

Then, install the Terraform with the apt package manager:

$ sudo apt install terraform -y

Check the Installed Version

To confirm the installation, display the version details of the installed “Terraform” using the command:

$ terraform --version

V1.3.0” version of the Terraform has been installed and ready to use on Ubuntu,

How to Remove Terraform on Ubuntu 22.04?

It can be uninstalled with all its configuration files from Ubuntu using the command:

$ sudo apt purge terraform -y

With the execution of the above command, the package “Terraform” has been removed from Ubuntu.

Conclusion

To install the Terraform in Ubuntu 22.04, we first import the GPG and then add the concerned repository. After that, update all the packages and install the Terraform using “$ sudo apt install terraform”. Terraform is the IAC tool that is used to manage infrastructure tasks. In this blog, the installation of the Terraform on Ubuntu 22.04 has been explained in detail.