Skip to content
terraform: command not found

terraform: command not found

DodaTech 2 min read

The “terraform: command not found” error means the Terraform CLI is not installed or not in your system PATH, preventing you from running any Terraform commands.

What It Means

Your shell cannot locate the terraform binary in any directory listed in the PATH environment variable. Terraform is either not installed, or its installation directory is not included in PATH.

Why It Happens

  • Terraform has never been installed on the system.
  • The installation was incomplete or corrupted.
  • The binary location (e.g. /usr/local/bin) is not in your PATH.
  • You’re using a minimal container image that does not include Terraform.
  • The version manager (tfenv) hasn’t activated the correct version.

How to Fix It

Step 1: Install Terraform with tfenv (recommended)

tfenv is a Terraform version manager similar to pyenv or nvm. It keeps multiple versions side by side.

  1. Install tfenv:
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
sudo ln -s ~/.tfenv/bin/* /usr/local/bin/
  1. Install and activate the latest Terraform version:
tfenv install latest
tfenv use latest
  1. Verify:
terraform --version
# Terraform v1.9.0 (or similar)

Step 2: Install via package manager

Ubuntu / Debian:

wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
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 update && sudo apt install terraform

macOS (Homebrew):

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Step 3: Download the binary directly

  1. Download from the official releases page:
wget https://releases.hashicorp.com/terraform/1.9.0/terraform_1.9.0_linux_amd64.zip
unzip terraform_1.9.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/
  1. Verify:
terraform --version

Step 4: Check your PATH

If Terraform is installed but not found:

which terraform || echo "Not in PATH"
echo "$PATH" | tr ':' '\n'

Add the Terraform directory to your shell config:

export PATH="$PATH:/usr/local/bin"
Do I need sudo to install Terraform?
Yes, installing Terraform system-wide requires sudo on Linux. If you lack sudo access, use tfenv which installs to your home directory, or download the binary to a directory like ~/bin and add it to your PATH.
How do I switch between Terraform versions?
If you installed tfenv, use tfenv list to see installed versions and tfenv use <version> to switch. This is essential when working across projects that require different Terraform versions.
What if 'terraform --version' returns a different version than expected?
Run which terraform to see which binary is being used. If you have multiple installations, the one appearing first in your PATH wins. Use tfenv or adjust your PATH order to control which version runs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro