| 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:
cat /etc/os-releasePRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntuThe VERSION_CODENAME value (resolute on 26.04) is what apt uses when you register the HashiCorp repository.
Confirm the package architecture apt will use:
dpkg --print-architectureamd64On 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.
sudo apt updateInstall wget and gpg if your image does not already ship them:
sudo apt install -y wget gpgOn 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:
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgThe 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:
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:
cat /etc/apt/sources.list.d/hashicorp.listdeb [arch=amd64 signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com resolute mainA 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:
sudo apt updateWith the HashiCorp index loaded, install the terraform package:
sudo apt install -y terraformReading 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:
command -v terraform/usr/bin/terraformOn an apt install the executable normally lands in /usr/bin.
Print the installed version:
terraform versionTerraform v1.15.8
on linux_amd64List top-level subcommands to confirm the binary runs:
terraform -helpUsage: 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 commandsTogether, 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:
apt-cache policy terraformterraform:
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 PackagesInstall an explicit older package version. When a newer build is already installed, allow the downgrade explicitly:
sudo apt install -y --allow-downgrades terraform=1.15.7-1Confirm apt downgraded the CLI:
terraform versionTerraform 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/installReturn to the newest repository build when you are done testing:
sudo apt install -y --only-upgrade terraformThree different version concepts often get mixed up:
- apt package version — the
1.15.7-1deb you install withapt install terraform=… - CLI
terraform versionoutput — the semantic version embedded in the binary required_versionin configuration — a constraint inside.tffiles 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:
sudo apt updateCheck whether apt sees a newer Terraform package:
apt list --upgradable 2>/dev/null | grep terraformWhen a row appears, install the upgrade:
sudo apt install -y --only-upgrade terraformConfirm the running binary:
terraform versionUpgrading Terraform itself is separate from upgrading provider plugins inside a working directory:
terraform init -upgradecan 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:
TF_ARCH=$(dpkg --print-architecture)amd64This 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:
case "$TF_ARCH" in
amd64|arm64) ;;
*) echo "Use the matching architecture from the Terraform releases page"; exit 1 ;;
esacSet 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:
TERRAFORM_VERSION="1.15.8"Download and verify the archive
Fetch the zip and its SHA256 checksum file:
cd /tmpDownload the Linux archive for your architecture and version:
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:
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS"Verify the zip against the published checksum:
sha256sum -c "terraform_${TERRAFORM_VERSION}_SHA256SUMS" --ignore-missingterraform_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:
sudo apt install -y unzipExtract and copy the executable into a directory on root's default PATH:
unzip -o "terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip"Copy the extracted binary into /usr/local/bin with executable permissions:
sudo install -m 0755 terraform /usr/local/bin/terraformRemove the temporary artifacts:
rm -f terraform "terraform_${TERRAFORM_VERSION}_linux_${TF_ARCH}.zip" "terraform_${TERRAFORM_VERSION}_SHA256SUMS"Verify the installation
Confirm location and file type:
command -v terraform/usr/local/bin/terraformInspect the ELF architecture to catch wrong-zip mistakes early:
file "$(command -v terraform)"/usr/local/bin/terraform: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, strippedIf 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):
mkdir -p ~/terraform-install-testMove into that directory before creating files:
cd ~/terraform-install-testCreate a minimal main.tf that only sets a Terraform core version constraint:
printf 'terraform {\n required_version = ">= 1.0"\n}\n' > main.tfInitialize the working directory:
terraform initInitializing 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:
terraform validateSuccess! 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:
terraform -install-autocompleteHashiCorp 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:
sudo apt remove -y terraformThe HashiCorp repository list and keyring remain after package removal. Delete them only when you no longer want apt to see HashiCorp packages:
sudo rm -f /etc/apt/sources.list.d/hashicorp.listRemove the signing keyring when you no longer plan to install HashiCorp packages:
sudo rm -f /usr/share/keyrings/hashicorp-archive-keyring.gpgManual binary installation
Delete the manually installed executable:
sudo rm -f /usr/local/bin/terraformterraform 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
- Install Terraform — HashiCorp Developer
- Terraform CLI documentation
- Terraform Associate 004 Learning Path
- HashiCorp Linux package repository
- Terraform releases and checksums
Summary
You installed Terraform on Ubuntu through HashiCorp's official apt repository and confirmed the CLI:
terraform versionandcommand -v terraformprove PATH resolution- A minimal
terraform init/terraform validatecycle in~/terraform-install-testruns 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
aptpath - 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.

