How to Install Terraform on Ubuntu 26.04

How to Install Terraform on Ubuntu 26.04
Published on Aug 27, 2026 Updated on Aug 28, 2026

Managing servers manually via clicks in a cloud console doesn't hold up at scale. It's slow, prone to human error, and difficult to repeat consistently across environments. The core challenges are threefold: inconsistency between setups, poor scalability as infrastructure grows, and no version history to fall back on when something breaks.

Terraform steps in to solve exactly those three problems by turning infrastructure management into code instead of clicks. It's HashiCorp's open-source Infrastructure as Code (IaC) tool that lets you define, provision, and manage cloud and on-premises infrastructure through declarative configuration files rather than manual console clicks.

You define your infrastructure (servers, networks, load balancer configurations, etc) in HCL (Terraform's configuration language). When you run the code, you get the same setup every time.

This guide walks through everything you need to get Terraform running on Ubuntu 26.04.

#Prerequisites

Before you begin, make sure you have the following:

A machine running Ubuntu 26.04 (physical, virtual, or cloud instance). You can spin up a high-performance and scalable Cloud VPS on Cherry Servers to follow along.

A sudo user configured on the instance

Linux Command-line knowledge

Scalable VPS Hosting

Deploy fast, secure VPS for websites, apps, and dev environments. Scale on demand, manage with full root access, and get 24/7 expert support.

#Installing Terraform on Ubuntu 26.04

There are various ways to install Terraform: from the recommended APT-based installation to alternative methods such as manual binary installation and Snap. We will explore each of these.

At the tail end of the tutorial, we will test Terraform’s capabilities by provisioning a local file with a populated random number. Lastly, we will clean up our workspace after testing out Terraform’s capabilities.

#Method 1: Installing from HashiCorp's Official APT Repository (Recommended)

This is the preferred method because it lets Terraform update alongside your regular system packages.

Step 1: Update your system and install prerequisites

To set sail, be sure to refresh your local APT repository.

Command Line
sudo apt update

Then install the required packages. These packages let you verify HashiCorp's GPG signature and manage the new repository source.

Command Line
sudo apt install -y gnupg software-properties-common curl

Step 2: Add HashiCorp's GPG signing key

With all the prerequisites in place, the next step is to add the GPG key. To achieve this, run:

Command Line
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

This downloads HashiCorp's public key and stores it in a keyring so that APT can verify that packages are genuine.

Step 3: Add the HashiCorp APT repository

The next step is to add the HashiCorp APT repository to the sources list directory. To achieve this, run the command:

Command Line
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

You can confirm the repository was added by running the command:

Command Line
ls  /etc/apt/sources.list.d | grep -i hashicorp

The output should display hashicorp.list, confirmation that the repository exists.

Outputhashicorp.list

Step 4: Install Terraform

Once added, refresh the local package index so that the system can start using the repository.

Command Line
sudo apt update

Then install Terraform using APT as follows:

Command Line
sudo apt install terraform -y
OutputInstalling:
  terraform

Summary:
  Upgrading: 0, Installing: 1, Removing: 0, Not Upgrading: 4
  Download size: 34.8 MB
  Space needed: 117 MB / 36.8 GB available

Once installed, check the version of Terraform installed:

Command Line
terraform --version

This is the output you should get.

OutputTerraform v1.15.8
on linux_amd64

#Method 2: Manual Binary Installation

In addition to installing from the APT repository, you can install Terraform manually from the binary package hosted on the official HashiCorp website. Let's see how to do this.

Step 1: Setting up an environment variable

To get started, you need to tell the shell to fetch the most current version dynamically. Set the environment variable as shown.

Command Line
TERRAFORM_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | grep -oP '"current_version":"\K[^"]+')

Step 2: Download and unzip the binary

Once you have specified the environment variable needed to download the latest version, run the wget command to download the latest binary.

Command Line
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"

The command will download the latest binary file in zipped format. When you run the lscommand, you should see the zip file in place. The current version at the time of writing this guide is 1.15.8.

Outputterraform_1.15.8_linux_amd64.zip

Step 3: Move the binary to your PATH

The next step is to unzip the archive. You can unzip it by referencing the Terraform environment variable as shown.

Command Line
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"

Or simply specify the full compressed file name terraform_1.15.8_linux_amd64.zip, as the argument.

Command Line
unzip terraform_1.15.8_linux_amd64.zip

NOTE: If the unzip command is missing, install it by running:

Command Line
sudo  apt install unzip -y

Next, move the terraform binary to the /usr/local/bin/ path.

Command Line
sudo mv terraform /usr/local/bin/

Step 4: Verify installation

Up to this point, Terraform has been successfully installed. To verify this, run the command:

Command Line
terraform -version

You should get the following output.

OutputTerraform v1.15.8
on linux_amd64

#Method 3: Install Terraform from snap

Lastly, you can install Terraform from snap as shown. The command instructs the snapd daemon to fetch and install the Terraform package from the Snap Store (Canonical's central repository of snaps).

Command Line
sudo snap install terraform --classic

The --classic flag disables snap's strict confinement, giving Terraform full access to your system so it can operate as intended. This means it can read and write files anywhere on your filesystem.

It also lets Terraform download provider plugin binaries (such as AWS and Azure) and actually provision the infrastructure that those configs define.

Once installed, confirm the existence of the Terraform snap:

Command Line
ls -lh /var/lib/snapd/snaps/ | grep -i terraform
Output-rw------- 2 root root  37M Jul 26 19:33 terraform_912.snap

Also, check the version:

Command Line
terraform -version

The output confirms successful installation of Terraform v1.15.8.

OutputTerraform v1.15.8
on linux_amd64

#Testing Terraform

In this section, we will put Terraform to the test by creating a simple file containing a random number. We will create a main.tf file. This will include elements that form part of Terraform's core workflow: providers, resources, state, and dependencies between resources.

The random and local providers will create a file containing a randomized hexadecimal number. Everything is fully local (no cloud credentials needed).

Create a working directory and navigate into it.

Command Line
mkdir terraform-test && cd terraform-test

Create the main.tf file as follows.

Command Line
cat > main.tf << 'EOF'
terraform{
  required_version = ">= 1.0"

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "~> 3.6"
    }
    local = {
      source  = "hashicorp/local"
      version = "~> 2.5"
    }
  }
}

# Generate a random ID
resource "random_id" "server" {
  byte_length = 4
}

# Write a local file that depends on the random resource
resource "local_file" "config" {
  filename = "${path.module}/server-config.txt"
  content  = <<-EOT
    server_id = ${random_id.server.hex}
    created_at = "test deployment"
  EOT
}

output "server_id" {
  value = random_id.server.hex
}

output "config_file_path" {
  value = local_file.config.filename
}
EOF

Initialize the working directory. This downloads all the required provider plugins and initializes the backend.

Command Line
terraform init

Towards the end of the output, you will see the following output, proof that everything went according to plan, and you can start using Terraform to provision resources.

Command Line
Terraform has been successfully initialized!

Next, run:

Command Line
terraform plan

The terraform plan command generates an execution plan, giving you a preview of exactly what changes Terraform will make to your infrastructure before anything actually happens. It’s a safe and non-destructive check that lets you see what will happen before resources are actually created.

Finally, run:

Command Line
terraform apply

The terraform apply command creates, updates, or destroys resources as needed so that your real infrastructure matches the desired state defined in your Terraform configuration files.

In this case, the command will create the sample file and populate it with a random number.

To confirm everything worked, run the ls command.

Command Line
ls -l

You should see three files: main.tf, terraform.tfstate and the server-config.txt file, created during deployment.

Outputtotal 12
-rw-r--r-- 1 root root  673 Jul 31 14:58 main.tf
-rwxr-xr-x 1 root root   52 Jul 31 15:07 server-config.txt
-rw-r--r-- 1 root root 2523 Jul 31 15:07 terraform.tfstate

You can preview the text file using the cat command to view its contents.

Command Line
cat server-config.txt

You should get two lines: the first containing the randomized ID, and the second containing the string created_at = "test deployment".

Outputserver_id = 00054778
created_at = "test deployment"

Additionally, you can run the command terraform show. The command reads the current local state file (terraform.tfstate) and displays all the managed resources, including their detailed attributes.

Command Line
terraform show

#Cleaning up

Once you're done installing Terraform and experimenting with your infrastructure, and need to tear down resources you no longer use, run the terraform destroy command. This makes cleanup just as simple as provisioning.

The terraform destroy command reads your current state file and removes every resource it manages, in the correct order, so you're not left manually deleting things through a cloud console.

Command Line
terraform destroy

Like apply, this command shows you a plan first, listing exactly what will be removed, and asks for confirmation before it acts. This is a deliberate safety check, since destroying infrastructure isn't reversible.

OutputDo you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure...
  Enter a value: yes

To skip the interactive prompt (useful in scripts or CI/CD pipelines), add the -auto-approve flag:

Command Line
terraform destroy -auto-approve

That said, you should exercise caution when using this flag since it removes the manual checkpoint that would otherwise catch a mistake before it becomes permanent. This output shows the last few lines that you will see confirming the deletion of the resources.

Outputlocal_file.config: Destroying... [id=6f6c1ac58833c77c52126918327150b6bab278b6]
local_file.config: Destruction complete after 0s
random_id.server: Destroying... [id=AAVHeA]
random_id.server: Destruction complete after 0s

Destroy complete! Resources: 2 destroyed.

#Removing Terraform

If you no longer need Terraform on your system, how you remove it depends on which installation method you used.

If you installed via APT, use the apt remove command as follows.

Command Line
sudo apt remove terraform

This removes the Terraform package but leaves configuration files and the HashiCorp repository source in place. To also clean those up:

Command Line
sudo apt purge terraform
sudo rm /etc/apt/sources.list.d/hashicorp.list
sudo rm /usr/share/keyrings/hashicorp-archive-keyring.gpg

If you installed the binary manually, removing it from /usr/local/bin/ will suffice.

Command Line
sudo rm /usr/local/bin/terraform

If you installed via Snap, remove it by running:

Command Line
sudo snap remove terraform

Whichever method you used, it's worth double-checking that Terraform is fully gone from your system:

Command Line
terraform -version

If the command isn't found, the removal was successful.

We have successfully installed Terraform on Ubuntu 26.04 and tested it out by creating a simple text file containing a randomized number in the project directory. In addition, we have also seen how to clean up your testing environment by running the terraform destroy command.

#Conclusion

With Terraform now installed and verified on your Ubuntu system, you're no longer stuck with manual infrastructure provisioning. Terraform will now handle the messy aspect of figuring out how to get there, tracking the current state of everything it manages and calculating the exact steps needed to move from where you are to where you want to be. What makes it stand out isn't just the automation; it's the discipline it brings. Every change is planned before it's applied, every configuration can be reviewed like any other piece of code, and every team member can see the full history of infrastructure decisions.

Cloud VPS Hosting

Starting at just $3.51 / month, get virtual servers with top-tier performance.

Share this article

Related Articles

Published on Jul 28, 2025 Updated on Nov 7, 2025

How to Use Variables in Terraform [With Examples]

Learn how to use, define, and organize Terraform variables with examples. Master input/output types, best practices, tfvars files, and environment variables.

Read More
Published on May 28, 2025 Updated on Nov 7, 2025

Terraform Cheat Sheet: Terraform Command Guide

Explore essential Terraform commands with examples in this cheat sheet. Learn to initialize, plan, apply, and manage cloud infrastructure efficiently.

Read More
Published on Dec 13, 2024 Updated on Nov 7, 2025

Terraform Registry Guide: How to Use Terraform Modules?

Learn to use Terraform Registry modules for efficient, reusable, and scalable infrastructure management. Explore tips on customization, best practices, and troubleshooting.

Read More
No results found for ""
Recent Searches
Navigate
Go
ESC
Exit