Terraform is an open-source Infrastructure as Code (IaC) tool by HashiCorp that enables users to define and create infrastructure in a declarative configuration language. It is commonly used to manage cloud resources from different providers such as AWS, Azure, and Google Cloud.
If you are using Ubuntu and would like to install Terraform on Ubuntu, this guide will guide you through step-by-step installation, including varying installation methods, best practices, and troubleshooting.
Why Use Terraform?

Terraform offers several advantages for infrastructure management:
- Automates Infrastructure Provisioning – No need for manual setup; Terraform automates cloud and on-prem infrastructure deployment.
- Ensures Consistency – Prevents configuration drift by maintaining infrastructure as code.
- Supports Multiple Cloud Providers – Manage AWS, Azure, GCP, Kubernetes, and more from a single tool.
- Enables Collaboration – Uses state files and version control to facilitate teamwork.
- Improves Scalability – Easily scale infrastructure up or down based on configuration changes.
Prerequisites
Before you install Terraform on Ubuntu, have the following available:
- An Ubuntu system (20.04, 22.04, or newer)
- A user with sudo privileges
- An internet connection
- Basic familiarity with the Linux command line
Method 1: Install Terraform from HashiCorp’s Official Repository
This is the preferred method as it guarantees that you receive the latest stable release directly from HashiCorp.
Step 1: Update System Packages
Update your system package list prior to installing Terraform:
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
Install dependencies required to add HashiCorp repository:
sudo apt install -y software-properties-common gnupg
Step 3: Add HashiCorp GPG Key
HashiCorp signs its software packages with a GPG key for security. Install the key into your system:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
Step 4: Add HashiCorp Repository
Now, install the official HashiCorp repository onto your Ubuntu 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
Step 5: Update Package List Again
Update package list after the new repository has been added:
sudo apt update
Step 6: Install Terraform
Install Terraform using:
sudo apt install -y terraform
Step 7: Check Installation
To ensure Terraform has been installed properly, verify its version:
terraform -version
Upon success, it will display the installed version of Terraform.
Method 2: Manually Install Terraform Using Binary Package
If you need more flexibility at the time of installation or a custom version, you can download and install Terraform on Ubuntu, binary manually.
Step 1: Download Terraform Binary
Visit the official release page of Terraform to download the latest one.
Download the latest Terraform binary with wget
(replace the version as necessary):

wget https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
Step 2: Install Unzip (if not already installed)
To unzip the file downloaded, install unzip:
sudo apt install -y unzip
Step 3: Extract the Terraform Binary
Unzip the Terraform binary file:
unzip terraform_1.6.0_linux_amd64.zip
Step 4: Move the Binary to /usr/local/bin
Move the extracted binary to a directory in your system’s $PATH
:
sudo mv terraform /usr/local/bin/
Step 5: Check Installation
Verify that Terraform has been installed and is accessible:
terrafrom -version
This should print the installed version of Terraform.
Method 3: Install Terraform via Snap
Another easy method of how to install Terraform on Ubuntu is through Snap, a package manager utilized in Ubuntu.
Step 1: Install Terraform using Snap
To install Terraform on Ubuntu, execute the following command:
sudo snap install terraform --classic
Step 2: Verify Installation
To verify Terraform has been installed successfully:
terraform -version
Configuring Terraform
After you install Terraform on Ubuntu, you must create a working directory and your first configuration file.
Step 1: Create a Working Directory
Create a new working directory with mkdir
and cd to change directories:
mkdir terraform-project
cd terraform-project
Step 2: Create a Terraform Configuration File
Use a text editor such as nano to open a file called main.tf
:
nano main.tf
Enter the following minimum Terraform configuration to launch an AWS EC2 instance:
provider "aws" {<br>region = "us-east-1"<br>}<br>resource "aws_instance" "example" {<br>ami = "ami-0c55b159cbfafe1f0"<br>instance_type = "t2.micro"<br>}
Save the file (CTRL+X, then Y and Enter).
Step 3: Initialize Terraform
Initialize Terraform prior to making any changes:
terraform init
Step 4: Validate Configuration
Verify your configuration file:
terraform validate
Step 5: Apply the Configuration
Apply Terraform to create resources (accept with yes when prompted):
terraform apply
Updating and Removing Terraform
1. Updating Terraform
If you have installed Terraform from the HashiCorp repository, update it with:
sudo apt update && sudo apt upgrade terraform -y
For Snap installations, do:
sudo snap refresh terraform
For manual installations, simply download and replace the binary with the new version.
2. Removing Terraform
Remove Terraform from the repository installation:
sudo apt remove --purge terraform -y
To uninstall the Snap installation:
sudo snap remove terraform
For manual installations, remove the binary:
sudo rm /usr/local/bin/terraform
Troubleshooting Common Issues
1. Command Not Found
If terraform -version responds with “command not found,” check if Terraform is included in your system’s $PATH
:
echo $PATH
If /usr/local/bin
is not present, append it:
export PATH=$PATH:/usr/local/bin
2. Permission Denied
If you receive a “permission denied” message, check that the binary has execution privileges:
sudo chmod +x /usr/local/bin/terraform
3. HashiCorp Repository Issues
If the repo addition with apt update still fails, attempt to re-add the repository and key. Furthermore, check your Ubuntu version with:
lsb_release -cs
Make sure your version is supported by HashiCorp’s repository.
Conclusion
Terraform is a robust tool used to manage infrastructure in a cost-effective way. It is easy to install on Ubuntu via the HashiCorp repository, a manual binary install, or Snap. With the instructions in this tutorial, you can install Terraform, define a minimal configuration, and provision cloud infrastructure.
Having learned how to install, configure, and debug Terraform enables you to now use Terraform successfully in your DevOps workflows
FAQs
1. What is Terraform?
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows users to define and provision infrastructure using a declarative configuration language across multiple cloud providers such as AWS, Azure, and Google Cloud.
2. Do I need to restart my system after installing Terraform?
No, a restart is not required. However, if Terraform is not recognized, try logging out and logging back in, or run:
source ~/.bashrc
3. How do I verify if Terraform is correctly installed on Ubuntu?
Run the following command:
terraform -version
It should output the installed Terraform version.