Skip to content
Ubuntu Linux

How to Install Terraform on Ubuntu Linux

Richard
Written by
Richard
Updated 4 min read
How to Install Google Chrome on Ubuntu Linux
How to Install Google Chrome on Ubuntu Linux

Terraform is a free infrastructure-as-code tool. You describe your servers, networks and other resources in plain text files, and Terraform builds, changes and tracks them for you. You don’t have to click through a web console. On Ubuntu, a plain sudo apt install terraform fails with a “package not found” style error. Terraform isn’t in Ubuntu’s default software list, so the system has nothing to install.

There are two ways around this. You can install Terraform as a Snap package, or you can add HashiCorp’s official software source and install from it. Either way you get the current release, for example Terraform 1.7.0. Your version number may be newer than the one shown in this guide, and that is fine. Both methods work on current Ubuntu LTS releases such as 22.04 and 24.04. You need a terminal and a user account that can run commands with sudo.

⚡ Quick Answer

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`.

Advertisement

Install Terraform on Ubuntu Linux via Snap

The Snap method is the quickest. One command in the terminal installs Terraform, and Snap then updates it in the background, so you never have to download new versions from the official website yourself.

Choose this method if you want the least work. Choose the repository method further down if you prefer to manage Terraform with apt, along with the rest of your system packages.

Advertisement

Snap is a package system developed by Canonical, the company behind Ubuntu. Developers bundle an app with the files it needs and publish it once. The same package then runs on different Linux distributions, so compatibility problems are rare. Snap is already included on standard Ubuntu installs.

Open a terminal by pressing Ctrl+Alt+T, or search for “Terminal” in the Activities menu. Then run the command below to install Terraform with Snap. Snap may ask for your password. Nothing shows on screen while you type it, which is normal.

🐧Bash / Shell
sudo snap install terraform --classic

When the command finishes, you should see a line saying Terraform was installed, along with the version number. If you ever want to remove Terraform, run the command below.

🐧Bash / Shell
sudo snap remove terraform

Install Terraform via its official repository

The second method uses HashiCorp’s own repository. You add HashiCorp’s GPG key, which is a security key that proves the packages really come from HashiCorp and were not altered. Then you add the repository to your list of software sources. After that, Terraform installs and updates through your normal package manager, the same way as any other Ubuntu package.

This takes a few more steps than Snap, but you get updates straight from HashiCorp along with your regular system updates. Run each command in order and check the output before moving to the next one.

First, run the command below to install the prerequisites. These are the small helper tools the later steps need to download the key and read the repository details.

🐧Bash / Shell
sudo apt install gnupg software-properties-common

Next, run the command below to download HashiCorp’s GPG key and save it on your system. Apt uses this key to check every Terraform package before it installs it.

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

Once the key is saved, run the command below to verify it. This step is optional, but it confirms the key was stored correctly and is the one you expected.

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

The command prints the key details, similar to the lines below. Compare the fingerprint with the one HashiCorp publishes on its website. If they don’t match, stop and don’t continue.

💻Code
#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]

Now run the command below to add the HashiCorp repository file to your system. It tells apt where to find Terraform and which key to trust for it. The command gives no output on success, so a quiet return to the prompt is what you want.

⬛Command Prompt
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 package index so apt picks up the new repository, then install Terraform. The command below does both. During the update you should see the HashiCorp repository listed in the output. If you don’t see it, go back and check the repository step.

🐧Bash / Shell
sudo apt update
sudo apt install terraform

Check that Terraform is installed by running the command below. It prints the installed version number. It works for both the Snap and the repository installs. No restart or sign-out is needed.

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

To remove a Terraform installed from the repository, use the command below. It removes the program only. The HashiCorp repository stays in your software sources, and any project files, configuration and state files in your own folders are left untouched.

🐧Bash / Shell
sudo apt remove terraform

That should do it! Terraform is now ready to use on your Ubuntu system.

Conclusion:

  • Terraform is an open-source infrastructure as code (IaC) tool for managing infrastructure resources from text files.
  • Ubuntu users can install Terraform with the Snap package manager, which updates itself, or from HashiCorp’s official repository, which updates through apt.
  • Installing Terraform on Ubuntu lets you create and manage resources such as VMs, network switches, and containers.
  • You can confirm the installation worked by running “terraform -version” in the terminal. It prints the installed version.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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