How to Install Terraform on Ubuntu Linux

This article explains how to install Terraform on Ubuntu Linux.

Terraform is an open-source infrastructure as code (IAC) tool that allows you to create, manage, and update infrastructure resources such as physical machines, VMs, network switches, containers, and more.

There are multiple ways to install Terraform on Ubuntu. It is available as a Snap package and can be installed using its official repository.

Terraform is not available in Ubuntu default repositories. If you try to install Terraform in Ubuntu using apt, you will get a standard error message that reads “Unable to locate package terraform.”

Installing Terraform on Ubuntu allows you to leverage its power while working on Ubuntu machines. With Terraform installed on Ubuntu, you can easily create and manage infrastructure resources such as physical machines, VMs, network switches, containers, and more.

Install Terraform on Ubuntu Linux via Snap

As mentioned above, there are multiple ways to install Terraform on Ubuntu Linux. One way is to use the Snap package manager.

Snap is a package management system developed by Canonical for Linux operating systems. It allows developers to easily distribute and update their software on different Linux distributions without worrying about compatibility issues.

To install Tarraform using Snap, run the command below.

sudo snap install terraform --classic

When you want to remove Terraform, run the command below.

sudo snap remove terraform

Install Terraform via its official repository

Another way to install Terraform is to use its official repository. Below are the steps to do that.

First, run the command below to install prerequisites.

sudo apt install gnupg software-properties-common

When you are done, run the command below to install HashiCorp’s GPG key to your system.

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

Once the GPG key is installed, verify it using the command below.

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

The command above will display the key details similar to the lines below:

#Output:
pub   rsa4096 2023-01-10 [SC] [expires: 2028-01-09]
      798A EC65 4E5C 1542 8C8E  42EE AA16 FCBC A621 E701
uid           [ unknown] HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>
sub   rsa4096 2023-01-10 [S] [expires: 2028-01-09]

After that, run the command below to install the repository file on your system.

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

Finally, update the install Terraform.

sudo apt update
sudo apt install terraform

You can verify that Terraform is installed by running the command below.

terraform -version
#Output:
Terraform v1.6.0
on linux_amd64

Remove it using the command below.

sudo apt remove terraform

That should do it!

Conclusion:

  • Terraform is a powerful open-source infrastructure as code (IAC) tool for managing infrastructure resources.
  • Ubuntu users can install Terraform using the Snap package manager or HashiCorp’s official repository.
  • Installing Terraform on Ubuntu enables easy management and creation of various infrastructure resources such as VMs, network switches, and containers.
  • Users can verify the successful installation of Terraform by running the command “terraform -version” in the terminal.

Frequently Asked Questions

What is Terraform and why should I use it?

Terraform is an open-source infrastructure as code (IAC) tool that enables you to create, manage, and update infrastructure resources efficiently. It simplifies the process of managing physical machines, VMs, network switches, and containers, making it a valuable tool for developers and system administrators.

How can I install Terraform on Ubuntu using Snap?

To install Terraform on Ubuntu using Snap, open your terminal and run the command 'sudo snap install terraform –classic'. This method is straightforward and ensures you have the latest version of Terraform.

What should I do if I encounter an 'Unable to locate package terraform' error?

This error occurs because Terraform is not available in the default Ubuntu repositories. To resolve this, you can install Terraform via Snap or by adding HashiCorp's official repository to your system.

How do I verify the installation of Terraform on Ubuntu?

After installing Terraform, you can verify the installation by running the command 'terraform -version' in your terminal. This will display the installed version of Terraform, confirming that the installation was successful.

Can I remove Terraform once it's installed, and how?

Yes, you can remove Terraform from your Ubuntu system. If you installed it via Snap, use the command 'sudo snap remove terraform'. If you installed it through the official repository, you can remove it using 'sudo apt remove terraform'.

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version