Install Terraform on Ubuntu
Here are two ways of installing Terraform on Ubuntu; using snap and using the official repository.
If you try to install Terraform in Ubuntu using apt, it will give you an error saying "Unable to locate package terraform":
And the reason behind this error is, Terraform is not available in Ubuntu's repository. But that doesn't mean you can't install it.
In this tutorial, I will walk you through two ways to install Terraform in Ubuntu:
- Using snaps (easy)
- Using Terraform repository
So let's start with the easy one.
Install Terraform using snaps in Ubuntu (easy)
If you ignore all the criticism for snaps, it works pretty well on servers and makes installation and management of packages super easy.
And the best part is it comes pre-configured in Ubuntu. So all you have to do is execute one command and Terraform will be installed:
sudo snap install terraform --classic
Once done, you can check the installed version of Terraform using the following command:
terraform -version
How to uninstall
If you don't want to have the snap version of Terraform, then, you can remove it using the following command:
sudo snap remove terraform
That's it!
Install Terraform using Terraform repository
In this method, I will show you how you can add Hashicorp's (the company behind Terraform) repository step by step to install Terraform.
First, install the prerequisites of Terraform using the following command:
sudo apt install gnupg software-properties-common
Next, install Hashicorp's GPG key to your system using the following:
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
Once done, you can verify the GPG key's fingerprint by executing the given command:
gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint
Finally, you can add the Terraform repository using the following:
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
To take effect from the changes, update the repository index:
sudo apt update
And then, install Terraform:
sudo apt install terraform
If you want to verify the installation, you can check the installed version:
terraform -version
How to uninstall
If you don't want to keep Terraform installed on your system, it can easily be removed using the apt remove command:
sudo apt remove terraform
Optionally, you can also remove the repository from your system.
Wrapping Up
This was a quick tutorial on how you can install Terraform on Ubuntu in the easiest way possible.
And I really hope installing Terraform is no longer a complex task for you.
Had some errors while following this tutorial? Leave a comment and I'll be at your help ASAP.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.