How to Install Terraform on Ubuntu Linux
You install Terraform on Ubuntu Linux to manage your infrastructure as code, defining and provisioning resources like servers and networks using simple configuration files.
Terraform is an open-source Infrastructure as Code (IaC) tool that automates the creation, modification, and versioning of your infrastructure.
You can install Terraform on Ubuntu using its official repository or as a Snap package, as it’s not part of Ubuntu’s default repositories. Attempting `sudo apt install terraform` will likely fail, showing an “Unable to locate package” error. Using the official repository ensures you get the latest version, such as Terraform 1.7.0.
This process lets you harness Terraform’s power directly from your Ubuntu machine for efficient infrastructure management.
Install Terraform on Ubuntu using Snap with `sudo snap install terraform –classic`, or by adding HashiCorp’s official repository and then running `sudo apt update && sudo apt install terraform`. Verify the installation with `terraform -version`.
Install Terraform on Ubuntu Linux via Snap
Installing Terraform on Ubuntu Linux using Snap is a straightforward method that quickly gets you the latest version.
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
You can install Terraform on Ubuntu Linux using HashiCorp’s official repository, which is a reliable way to get updates straight from the source.
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.
How to check if Terraform is installed in Ubuntu?
How do I check if Terraform is installed on my system? You can run terraform –version in your terminal or command prompt to see if Terraform is installed and view the installed version.
Do you have to install Terraform?
To use Terraform, you first need to install it. HashiCorp distributes Terraform as a binary package. You can also install Terraform using popular package managers.
Is Terraform GUI or CLI?
Terraform is CLI-driven by default, which can be challenging for teams managing large-scale infrastructure or enforcing organizational policies.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!