The article provides a guide on installing Terraform, an open-source Infrastructure as Code tool, on Ubuntu Linux. Terraform is installable via two common methods: through the Snap package manager or its official repository. Despite not being in Ubuntu’s default repositories, the guide walks through command line inputs, enabling easy installation and management of infrastructure resources.
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 the power of Terraform 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:
This post showed you how to install Terraform on Ubuntu Linux. Please use the comments form below if you find errors or have something to add.