Install Terraform

Install Terraform on your machine — Terraform foundations.

Focus: install terraform on your machine

Sponsored

You've heard the buzzword Infrastructure as Code, and you're ready to actually run Terraform. But before you can write your first plan, you need to get the binary on your machine — and that often trips up beginners. Between version managers, PATH issues, and shell quirks, the installation step can feel more like a chore than a first win. This lesson cuts through the noise: by the end, you'll have Terraform installed, verified, and ready for the next step in your Terraform foundations path, whether you're on macOS, Linux, or Windows.

The problem this lesson solves

Without a working Terraform binary, none of the magic happens. You can't run terraform init, terraform plan, or terraform apply. You'll see the dreaded command not found error, and your learning momentum stalls. The setup also creates friction: which version should you install? Why do some tutorials use tfenv and others use Homebrew? What about corporate machines with locked-down permissions? This lesson eliminates that friction. You'll understand the installation options, choose the right one for your environment, and verify that everything works — so you can focus on learning Terraform's core concepts, not fighting your operating system.

Core concept / mental model

Think of Terraform as a compiler for your infrastructure. Just like gcc or python3 turns your code into something the machine can execute, Terraform takes your .tf configuration files and turns them into API calls against your cloud provider. But to run that compiler, you need the executable installed and accessible in your shell.

The mental model breaks down into three parts:

  • Binary distribution: Terraform ships as a single executable file. No complex dependencies, no runtime environment like Python or Node.js.
  • Installation location: The binary lives in a directory that your shell searches for commands — that's your PATH.
  • Version management: Different projects may need different Terraform versions. A version manager like tfenv (macOS/Linux) or tfswitch helps you switch quickly.

Pro tip: Think of the install as a three-step loop: download, place, verify. You're not just getting a file; you're making it discoverable and confirming it runs.

How it works step by step

Installing Terraform follows a consistent pattern across operating systems. Here's the generic flow:

  1. Download the package for your OS and architecture (usually 64-bit).
  2. Extract the archive to get the terraform binary.
  3. Place the binary in a directory on your PATH (e.g., /usr/local/bin on macOS/Linux, or a user directory on Windows).
  4. Verify the checksum (optional but recommended for security).
  5. Test the binary with terraform version.

This approach works everywhere, but you'll often use package managers or scripts that automate steps 1–3.

Hands-on walkthrough

Let's get Terraform installed on your machine. We'll cover the most common methods for each OS, starting with the quickest.

macOS (Homebrew)

If you use Homebrew, the easiest method is:

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

Then verify:

terraform version

Expected output (versions may vary):

Terraform v1.9.8
on darwin_amd64

Linux (apt or manual)

On Ubuntu/Debian, use the official HashiCorp APT repository:

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
curl -fsSL 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

Verify:

terraform -v

Alternatively, for any Linux distro, manually download the binary:

wget https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_amd64.zip
unzip terraform_1.9.8_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform version

Windows (Chocolatey or manual)

With Chocolatey:

choco install terraform

Manual download: go to terraform.io/downloads, get the Windows 64-bit zip, unzip it, and move terraform.exe to a folder in your PATH (e.g., C:\terraform). Add that folder to PATH via System Properties > Environment Variables.

Use a version manager (recommended for learning)

Version managers let you switch easily — useful when following tutorials targeting older versions.

macOS/Linux with tfenv:

git clone https://github.com/tfutils/tfenv.git ~/.tfenv
sudo ln -s ~/.tfenv/bin/* /usr/local/bin
tfenv install latest
tfenv use latest
terraform version

Windows with tfswitch:

choco install tfswitch

Verify with a quick project

Create a temporary directory and test the basic workflow:

mkdir ~/terraform-test && cd ~/terraform-test
touch main.tf

Add this content to main.tf:

resource "null_resource" "example" {
  triggers = {
    always_run = timestamp()
  }

  provisioner "local-exec" {
    command = "echo Terraform works on this machine!"
  }
}

Now run:

terraform init
terraform apply -auto-approve

Expected output includes:

Terraform has been successfully initialized!
...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Pro tip: The null_resource trick is a safe way to verify Terraform execution without touching real cloud services — perfect for a smoke test.

Compare options / when to choose what

Method Ease Version control Platform Best for
Package manager (brew/apt/choco) Easy Fixed to repo All Quick start, production consistency
Official binary download Moderate Manual All A single install, no extra tools
Version manager (tfenv/tfswitch) Moderate Excellent macOS/Linux (tfenv), Windows (tfswitch) Developing across multiple projects
Docker image Easy Via image tag Cross-platform CI/CD or isolated environments

Choose the package manager for simplicity and reproducibility on one machine. Choose a version manager if you'll work on several projects with different Terraform versions. For CI pipelines, the Docker image (hashicorp/terraform:1.9.8) is the standard.

Troubleshooting & edge cases

command not found: terraform

Your binary isn't in PATH. Check the installation directory and add it:

echo $PATH   # macOS/Linux
$env:PATH    # PowerShell

Permission denied on Linux/macOS

The binary lacks execute permissions. Fix with:

chmod +x terraform

Wrong architecture (e.g., ARM vs x86)

You downloaded the wrong package. Check your CPU:

uname -m   # macOS/Linux

For Apple Silicon (M1/M2), use the arm64 build; on Intel, amd64.

Homebrew hashicorp/tap not found

Make sure you ran brew tap hashicorp/tap first. If you get a “No available formula” error, tap again and update:

brew tap hashicorp/tap
brew update

Windows PATH not updating after adding folder

Open a new terminal — the environment variable refresh isn't automatic. Also verify the folder contains terraform.exe, not just the ZIP.

TLS certificate errors on download

If you're behind a corporate proxy, certificate validation may fail. Use the package manager or download from a trusted mirror, and check your proxy settings.

What you learned & what's next

You can now install Terraform on your machine, check its version, and run a simple init/plan/apply workflow. You understand the difference between package managers and version managers, and you know how to troubleshoot common PATH and permission issues. That's the foundation for everything ahead.

Next, you'll install the AWS CLI on your Mac so you can give Terraform the credentials it needs to manage real cloud resources. That lesson will show you how to configure your first provider — a critical step you'll use in every module of this track.

Now that your binary is ready, the real Terraform journey begins. Let's go!

Practice recap

Create a snippets directory in your home folder. Inside, write a main.tf with a null_resource that prints your name, then run terraform init and terraform apply. If you feel adventurous, install tfenv and switch between two Terraform versions to see how easy it becomes. This hands‑on loop will cement the install and prep you for the AWS CLI lesson.

Common mistakes

  • Forgetting to unzip the binary before moving it — running mv terraform.zip /usr/local/bin/ leaves a useless archive.
  • Using sudo with package managers when you don't need it, or using it for tfenv links and creating permission headaches.
  • Choosing a 32‑bit build (you almost certainly need 64‑bit), which leads to cannot execute binary errors.
  • Editing PATH on Windows but forgetting to restart the terminal, so the command still isn't found.

Variations

  1. Use asdf with the Terraform plugin to manage multiple project toolchains (Terraform, Node, Python) in one version manager.
  2. Run Terraform in a Docker container or a devcontainer for a clean, reproducible environment without touching your host OS.
  3. On Windows, you can use WSL2 and follow the Linux install path — many DevOps teams prefer this workflow.

Real-world use cases

  • A developer setting up a personal laptop to practice Terraform with AWS free tier, using brew or a version manager.
  • A CI runner in GitHub Actions installs Terraform via the official hashicorp/setup-terraform action before running terraform plan.
  • A production server has Terraform pinned to a specific version via a configuration management tool (Ansible) to ensure consistency across deployments.

Key takeaways

  • Terraform is a single binary — no runtime dependencies, so installation is just download + PATH placement.
  • Always verify the version with terraform version to confirm the installation succeeded.
  • Use version managers when juggling multiple Terraform versions across projects.
  • The Docker image offers a clean, portable way to run Terraform in CI/CD.
  • Common failure points are PATH, permissions, and architecture mismatches — all quickly fixable.
  • Your next step is configuring cloud creds (e.g., AWS CLI) to give Terraform the keys to manage infrastructure.

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.