Terraform Tutorial — Install Terraform on Linux
Installing Terraform on Linux is straightforward — you can use the official HashiCorp repository (recommended) or download the binary manually. This page covers both methods plus tfenv, a version manager for teams.
Method 1: Official HashiCorp Repository (Recommended)
Using the package repository keeps Terraform updated through your system’s package manager.
Ubuntu / Debian
$ sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
$ wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null
$ 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
$ sudo apt-get update && sudo apt-get install terraform
CentOS / RHEL / Amazon Linux
$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
$ sudo yum install terraform
Verify the Installation
After installing, confirm Terraform is available:
$ terraform version
Terraform v1.7.5
on linux_amd64
The version number will vary. As long as you see a version output, the installation was successful.
Method 2: Manual Binary Download
If you can’t add a repository (restricted environments, air-gapped systems), download the binary directly.
$ TERRAFORM_VERSION="1.7.5"
$ wget "https://releases.hashicorp.com/hashicorp/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
$ unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
$ sudo mv terraform /usr/local/bin/
$ terraform version
Terraform v1.7.5
on linux_amd64
💡 Tip:
/usr/local/bin/is on most systems’ PATH by default. Ifterraform versiondoesn’t work, check your PATH withecho $PATH.
Method 3: tfenv — Terraform Version Manager
tfenv is like nvm for Node.js — it lets you install and switch between multiple Terraform versions. This is essential for teams where different projects use different versions.
Install tfenv
$ git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
$ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
Install a Terraform Version
$ tfenv install 1.7.5
Installing Terraform v1.7.5
...
Installation of terraform v1.7.5 successful
$ tfenv use 1.7.5
Switching default version to v1.7.5
$ terraform version
Terraform v1.7.5
on linux_amd64
Pin a Version Per Project
Create a .terraform-version file in your project root:
$ echo "1.7.5" > .terraform-version
When anyone enters the project directory, tfenv automatically uses the specified version. This prevents “it works on my machine” issues caused by version differences.
Pinning Terraform Versions in Configuration
Even without tfenv, you should pin the Terraform version in your config to prevent teammates from accidentally running an incompatible version:
terraform {
required_version = ">= 1.7.0, < 2.0.0"
}
If someone runs a version outside this range, Terraform refuses to execute:
Error: Unsupported Terraform Core version
This configuration does not support Terraform version 1.5.0. To proceed,
either choose another supported version or update this version constraint.
Enable Shell Completion
Terraform supports tab completion for commands and arguments:
$ terraform -install-autocomplete
This adds a line to your ~/.bashrc (or ~/.zshrc). Restart your shell or run source ~/.bashrc to activate it.
After enabling, you can type terraform pl and press Tab to auto-complete to terraform plan.
What’s Next?
If you’re on Linux, you’re now set up. Next, we’ll cover installation on macOS and Windows — or you can skip ahead to Setting Up Cloud Credentials if you’re ready.