Install Terraform on Ubuntu

Tested on Ubuntu 26.04 LTS (Resolute Raccoon)
Package terraform 1.15.8-1
Applies to Ubuntu
Lab environment Ubuntu VM — continue to Terraform lab environment on Ubuntu for provider and Docker labs
Privilege sudo or root
Scope Install and maintain the Terraform CLI on Ubuntu from the official HashiCorp apt repository or a verified release binary, including version checks, upgrades, shell completion, uninstall, and installation troubleshooting. Does not cover provider configuration, remote state, or full init/plan/apply workflows.
Related guides Terraform lab environment on Ubuntu
apt command
check Ubuntu version
which command
install cURL on Ubuntu

Use HashiCorp's official apt repository when you want Terraform on Ubuntu with normal package upgrades through apt. This guide was tested on Ubuntu 26.04 LTS.

  • Method 1 — apt repository path, verification, pinning a version, and upgrades
  • Method 2 — verified release binary when apt is not an option

After either install path, you run a shared CLI smoke test, optional shell completion, and uninstall steps.


Prerequisites

You need a supported Ubuntu release, outbound HTTPS to HashiCorp mirrors, and a shell with sudo access. Confirm the OS and CPU architecture before adding the repository — HashiCorp packages are architecture-specific.

Check the distribution name and release:

bash
cat /etc/os-release
output
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu

The VERSION_CODENAME value (resolute on 26.04) is what apt uses when you register the HashiCorp repository.

Confirm the package architecture apt will use:

bash
dpkg --print-architecture
output
amd64

On 64-bit Intel/AMD Ubuntu systems you should see amd64. ARM64 hosts use arm64 packages from the same repository layout.


Choose an install method

Method Best for Jump to
HashiCorp apt repository Most Ubuntu workstations and servers — installs current stable Terraform and supports apt upgrade Method 1
Official release binary Locked-down hosts without extra apt repos, air-gapped copies, or a version not published in apt Method 2

Method 1 is the default path on Ubuntu 26.04.


Method 1: Install Terraform from the HashiCorp APT repository

Install repository prerequisites

Install the small tools HashiCorp's apt instructions expect. Refresh indexes first; you do not need a full dist-upgrade just to add Terraform.

bash
sudo apt update

Install wget and gpg if your image does not already ship them:

bash
sudo apt install -y wget gpg

On a minimal cloud image these packages may already be present. If wget is missing, see install cURL on Ubuntu — either wget or curl can fetch the signing key, but the commands below follow HashiCorp's current wget example.

Add the HashiCorp signing key

Download HashiCorp's apt signing key and store it in /usr/share/keyrings/ so apt can verify packages without the deprecated apt-key workflow:

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

The pipeline downloads the key over HTTPS, and gpg --dearmor converts it into the binary keyring format apt reads through signed-by.

Add the HashiCorp repository

Register the repository with your Ubuntu codename and architecture:

bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

$(dpkg --print-architecture) limits the line to your CPU architecture. The grep/lsb_release segment resolves resolute on Ubuntu 26.04 so apt requests the correct suite from apt.releases.hashicorp.com.

Confirm the file contents before running apt install:

bash
cat /etc/apt/sources.list.d/hashicorp.list
output
deb [arch=amd64 signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com resolute main

A typo in this one-line file is a common reason apt later reports that it cannot locate package terraform.

Install Terraform

Refresh indexes with the new repository enabled, then install the package:

bash
sudo apt update

With the HashiCorp index loaded, install the terraform package:

bash
sudo apt install -y terraform
output
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  terraform
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/XX MB of archives.
After this operation, 117 MB of additional disk space will be used.
Selecting previously unselected package terraform.
(Reading database ... 8734 files and directories currently installed.)
Preparing to unpack .../terraform_1.15.8-1_amd64.deb ...
Unpacking terraform (1.15.8-1) ...
Setting up terraform (1.15.8-1) ...

The exact download size varies by release; the important line is Setting up terraform.

Verify the installation

Check that your shell resolves the binary:

bash
command -v terraform
output
/usr/bin/terraform

On an apt install the executable normally lands in /usr/bin.

Print the installed version:

bash
terraform version
output
Terraform v1.15.8
on linux_amd64

List top-level subcommands to confirm the binary runs:

bash
terraform -help
output
Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands

Together, command -v, terraform version, and terraform -help prove PATH resolution, execution, and CLI availability. You do not need a cloud account for these checks.

Install a specific version

Enterprise and certification labs sometimes require an exact CLI build. With the HashiCorp repository enabled, list published versions:

bash
apt-cache policy terraform
output
terraform:
  Installed: 1.15.8-1
  Candidate: 1.15.8-1
  Version table:
 *** 1.15.8-1 500
        500 https://apt.releases.hashicorp.com resolute/main amd64 Packages
        100 /var/lib/dpkg/status
     1.15.7-1 500
        500 https://apt.releases.hashicorp.com resolute/main amd64 Packages
     1.15.6-1 500
        500 https://apt.releases.hashicorp.com resolute/main amd64 Packages

Install an explicit older package version. When a newer build is already installed, allow the downgrade explicitly:

bash
sudo apt install -y --allow-downgrades terraform=1.15.7-1

Confirm apt downgraded the CLI:

bash
terraform version
output
Terraform v1.15.7
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.15.8. You can update by downloading from https://developer.hashicorp.com/terraform/install

Return to the newest repository build when you are done testing:

bash
sudo apt install -y --only-upgrade terraform

Three different version concepts often get mixed up:

  • apt package version — the 1.15.7-1 deb you install with apt install terraform=…
  • CLI terraform version output — the semantic version embedded in the binary
  • required_version in configuration — a constraint inside .tf files that Terraform evaluates when you run commands in a directory

Installing a specific apt package version does not automatically change required_version in your code, and a matching required_version block does not install a different CLI build by itself. A later sudo apt upgrade can still replace the package unless you take separate steps to hold it — this article installs a version for testing, then returns to the current repository build.

When apt no longer ships the build you need, use Method 2 instead of forcing an unavailable package name.

Upgrade Terraform

With the HashiCorp repository configured, upgrading the CLI follows the normal apt maintenance path:

bash
sudo apt update

Check whether apt sees a newer Terraform package:

bash
apt list --upgradable 2>/dev/null | grep terraform

When a row appears, install the upgrade:

bash
sudo apt install -y --only-upgrade terraform

Confirm the running binary:

bash
terraform version

Upgrading Terraform itself is separate from upgrading provider plugins inside a working directory:

  • terraform init -upgrade can upgrade both modules and providers
  • Provider selections are recorded in .terraform.lock.hcl
  • Keep CLI upgrades on the apt path and provider or module upgrades inside each Terraform project

Method 2: Install Terraform manually from the official binary

Use the release archive when you cannot add apt repositories or when you need a portable copy under /usr/local/bin. The steps below match HashiCorp's Linux binary workflow.

Determine architecture and release version

Map the architecture HashiCorp uses in release zip filenames:

bash
TF_ARCH=$(dpkg --print-architecture)
output
amd64

This walkthrough supports Ubuntu amd64 and arm64 — their dpkg architecture names match HashiCorp's Terraform archive suffixes in terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip.

HashiCorp also publishes Terraform for additional Linux architectures (AMD64, ARM64, ARM, 386, and S390X), but those require selecting the corresponding archive manually from the official releases page. The commands below cover only the two Ubuntu architectures demonstrated here.

Reject any other dpkg architecture before downloading:

bash
case "$TF_ARCH" in
  amd64|arm64) ;;
  *) echo "Use the matching architecture from the Terraform releases page"; exit 1 ;;
esac

Set the release version to install. This example uses 1.15.8 — the current stable build at publication time. Check the official Terraform install page when you need another version:

bash
TERRAFORM_VERSION="1.15.8"

Download and verify the archive

Fetch the zip and its SHA256 checksum file:

bash
cd /tmp

Download the Linux archive for your architecture and version:

bash
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip"

Fetch the matching SHA256 checksum file from the same release directory:

bash
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS"

Verify the zip against the published checksum:

bash
sha256sum -c "terraform_${TERRAFORM_VERSION}_SHA256SUMS" --ignore-missing
output
terraform_1.15.8_linux_amd64.zip: OK

--ignore-missing skips checksum lines for platforms you did not download. Do not skip this step on production hosts.

Install the binary

Install unzip if the extractor is not already on the system — the HashiCorp archive is a zip file, not a bare binary:

bash
sudo apt install -y unzip

Extract and copy the executable into a directory on root's default PATH:

bash
unzip -o "terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip"

Copy the extracted binary into /usr/local/bin with executable permissions:

bash
sudo install -m 0755 terraform /usr/local/bin/terraform

Remove the temporary artifacts:

bash
rm -f terraform "terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip" "terraform_${TERRAFORM_VERSION}_SHA256SUMS"

Verify the installation

Confirm location and file type:

bash
command -v terraform
output
/usr/local/bin/terraform

Inspect the ELF architecture to catch wrong-zip mistakes early:

bash
file "$(command -v terraform)"
output
/usr/local/bin/terraform: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped

If you previously installed Terraform from apt, type -a terraform may list both /usr/bin/terraform and /usr/local/bin/terraform. The first match on your PATH wins — see the troubleshooting table below if the wrong binary runs.

HashiCorp also publishes OpenPGP signatures for releases. Teams with formal supply-chain checks can verify signatures after importing HashiCorp's signing key; that optional step is documented on developer.hashicorp.com/terraform/install.


Test the Terraform CLI

After either install method, run a tiny configuration in an isolated directory so you do not collide with a broader lab tree (for example ~/terraform-labs/ from Terraform lab environment on Ubuntu):

bash
mkdir -p ~/terraform-install-test

Move into that directory before creating files:

bash
cd ~/terraform-install-test

Create a minimal main.tf that only sets a Terraform core version constraint:

bash
printf 'terraform {\n  required_version = ">= 1.0"\n}\n' > main.tf

Initialize the working directory:

bash
terraform init
output
Initializing the backend...

Initializing provider plugins...


Terraform has been successfully initialized!

Because this configuration only declares required_version and no providers or resources, terraform init does not need to download a provider plugin.

Validate syntax without creating infrastructure:

bash
terraform validate
output
Success! The configuration is valid.

init and validate confirm the CLI can parse configuration on disk. This article stops before plan or apply — those workflows belong in dedicated Terraform command lessons.


Enable Terraform shell completion

Terraform can install tab completion for Bash and Zsh with one command:

bash
terraform -install-autocomplete

HashiCorp expects ~/.bashrc or ~/.zshrc to exist before you run that command. Restart the shell or run source ~/.bashrc or source ~/.zshrc so the updated profile loads. Completion is optional — installation already succeeded if terraform version works.


Uninstall Terraform from Ubuntu

APT installation

Remove the package:

bash
sudo apt remove -y terraform

The HashiCorp repository list and keyring remain after package removal. Delete them only when you no longer want apt to see HashiCorp packages:

bash
sudo rm -f /etc/apt/sources.list.d/hashicorp.list

Remove the signing keyring when you no longer plan to install HashiCorp packages:

bash
sudo rm -f /usr/share/keyrings/hashicorp-archive-keyring.gpg

Manual binary installation

Delete the manually installed executable:

bash
sudo rm -f /usr/local/bin/terraform
IMPORTANT
Uninstalling the Terraform binary only removes the CLI from your system. It does not destroy VMs, networks, or other infrastructure Terraform already created. Destroying managed infrastructure still requires terraform destroy (or provider-specific cleanup) in the project that created it.

Your *.tf files, .terraform/ directories, and terraform.tfstate files are left untouched by package removal.


Troubleshooting

Symptom Likely cause Fix
terraform: command not found Binary not installed or not on PATH Run command -v terraform and echo "$PATH"; reinstall with apt or restore /usr/local/bin/terraform
Unable to locate package terraform Missing or wrong HashiCorp apt source grep -R apt.releases.hashicorp.com /etc/apt/sources.list /etc/apt/sources.list.d/ then sudo apt update
Repository signing / key errors Keyring path mismatch or stale key Confirm signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg matches the file created by gpg --dearmor; re-create the keyring with the Add the HashiCorp signing key commands if the file is missing
Exec format error when running terraform Architecture mismatch Compare uname -m, dpkg --print-architecture, and file "$(command -v terraform)"; x86_64 / amd64 hosts need the linux_amd64 zip, aarch64 / arm64 hosts need linux_arm64
Wrong version runs Multiple binaries on PATH type -a terraform and which terraform; remove stale copies under ~/bin or /usr/local/bin when they shadow the apt package in /usr/bin

References


NOTE
Terraform Associate 004 tests Terraform 1.12. Install the current stable CLI on Ubuntu for day-to-day use. Certification lessons call out 1.12-specific behavior where it differs from current defaults.

Summary

You installed Terraform on Ubuntu through HashiCorp's official apt repository and confirmed the CLI:

  • terraform version and command -v terraform prove PATH resolution
  • A minimal terraform init / terraform validate cycle in ~/terraform-install-test runs without cloud credentials

When apt cannot satisfy a version requirement:

  • The same release is available as a verified zip under /usr/local/bin

Day-to-day maintenance:

  • CLI upgrades stay on the apt path
  • Provider updates stay inside each working directory

If which terraform shows an unexpected path, check for multiple binaries before you debug provider errors.

Next, prepare a reusable practice layout in Terraform lab environment on Ubuntu once terraform version reports the build you want.


Frequently Asked Questions

1. How do I install Terraform on Ubuntu?

Add the official HashiCorp apt repository with the signed-by keyring, run sudo apt update, then sudo apt install terraform. Verify with terraform version and command -v terraform (typically /usr/bin/terraform).

2. What is the recommended way to install Terraform on Ubuntu?

Use HashiCorp apt repository at apt.releases.hashicorp.com. It installs the current stable Terraform build and lets you upgrade with sudo apt install --only-upgrade terraform like any other Ubuntu package.

3. How do I install a specific Terraform version on Ubuntu?

List versions with apt-cache policy terraform, then install an exact deb with sudo apt install --allow-downgrades terraform=1.15.7-1 when downgrading from a newer package. When the repository no longer ships the version you need, download the matching linux_amd64 or linux_arm64 zip from releases.hashicorp.com and install the binary under /usr/local/bin after sha256sum verification.

4. Why does Ubuntu say terraform command not found after install?

The binary is missing from PATH or an older manual copy shadows the apt package. Run command -v terraform, type -a terraform, and echo $PATH. Reinstall with sudo apt install terraform or confirm /usr/local/bin/terraform is the version you expect.

5. How do I upgrade Terraform on Ubuntu?

Run sudo apt update, check apt list --upgradable for terraform, then sudo apt install --only-upgrade terraform. Confirm with terraform version. Upgrading the Terraform CLI is separate from upgrading provider plugins with terraform init -upgrade.

6. How do I uninstall Terraform from Ubuntu?

For the apt package run sudo apt remove terraform. Remove /etc/apt/sources.list.d/hashicorp.list and /usr/share/keyrings/hashicorp-archive-keyring.gpg if you no longer want the repository. For a manual install run sudo rm /usr/local/bin/terraform. Uninstalling the binary does not destroy infrastructure Terraform already created.

7. Does Terraform Associate 004 require Terraform 1.12 on Ubuntu?

The exam tests Terraform 1.12 behavior, but your Ubuntu install should track the current stable release from HashiCorp. Install the latest CLI with apt and use version-specific lessons when Associate objectives differ from current defaults.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)