Install Terraform

Install the Terraform CLI, then verify it with terraform version.

Syntaxterraform version

Terraform is a single self-contained binary. You install the Terraform CLI and run all commands from your terminal inside a directory of .tf files.

Common install methods

  • macOSbrew install hashicorp/tap/terraform
  • Windowschoco install terraform or download the zip.
  • Linux — add the HashiCorp apt/yum repo, or unzip the release binary onto your PATH.

Verify the install

Run terraform version. If it prints a version number, you are ready to go.

Example

Example · bash
# Verify Terraform is installed and on your PATH
terraform version
# Terraform v1.9.5
# on linux_amd64

# See all available commands
terraform -help

When to use it

  • A new team member installs the Terraform CLI on their Mac in under two minutes using Homebrew, ready to run plans immediately.
  • A CI/CD pipeline Docker image installs a pinned Terraform version from the HashiCorp apt repository to guarantee reproducible builds.
  • An operator verifies terraform version after upgrading to confirm the new binary is on PATH before running production applies.

More examples

Install on macOS with Homebrew

Installs the official HashiCorp Terraform CLI on macOS using Homebrew and verifies the installed version.

Example · bash
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
terraform version

Install on Ubuntu/Debian

Adds the official HashiCorp apt repository, installs Terraform, and confirms the version on Debian-based systems.

Example · bash
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 update && sudo apt install terraform
terraform version

Pin version in CI Dockerfile

Pins an exact Terraform version in a Dockerfile so every CI run uses the same binary regardless of registry updates.

Example · dockerfile
FROM ubuntu:22.04
ARG TERRAFORM_VERSION=1.9.0
RUN apt-get update && apt-get install -y wget unzip \
 && wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
 && unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin \
 && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip
RUN terraform version

Discussion

  • Be the first to comment on this lesson.