Terraform Infrastructure as CodemacOSTerraformUbuntuWindows

Article & Tutorial

Install Terraform on Ubuntu, Windows and macOS

Install Terraform from official sources on Ubuntu, Windows and macOS, verify the CLI, initialize a project and resolve common setup errors.

Terraform installation workflow across Ubuntu, Windows and macOS with successful command-line verification
Terraform installation workflow across Ubuntu, Windows and macOS with successful command-line verification
Contents

Last reviewed: September 2026

Terraform is distributed as a single command-line executable. Install it from an official HashiCorp channel, confirm that your shell can find it, and then initialize a small project to verify provider downloads and local configuration.

Before you install

  • Confirm whether your computer uses x86-64 or Arm64.
  • Remove or rename an older Terraform executable if it could appear earlier in PATH.
  • Use the official HashiCorp download and checksum pages. Do not install binaries copied from an unknown mirror.
  • For team environments, agree on a supported Terraform version and enforce it in configuration or automation.

Install Terraform on Ubuntu

HashiCorp publishes a signed APT repository for supported Debian and Ubuntu systems. Follow the current official installation page to add the HashiCorp signing key and repository for your distribution, then refresh package metadata and install Terraform.

install-terraform-ubuntu.sh
sudo apt update
sudo apt install terraform

If the package cannot be located, verify that the HashiCorp repository entry matches your Ubuntu release and that its signing key is present. Avoid disabling signature verification.

Install Terraform on Windows

  1. Open the official Terraform installation page and download the ZIP for Windows that matches your processor architecture.
  2. Compare the archive checksum with the checksum published by HashiCorp.
  3. Extract terraform.exe to a controlled directory such as C:\Tools\Terraform.
  4. Add that directory to your user or system PATH.
  5. Close and reopen PowerShell or Command Prompt so the updated PATH is loaded.

A package manager can automate upgrades, but first confirm who maintains the package and which version it provides. The direct HashiCorp download keeps the source and checksum explicit.

Install Terraform on macOS

HashiCorp maintains a Homebrew tap for macOS. After installing Homebrew, add the tap and install Terraform.

install-terraform-macos.sh
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

For a later upgrade through the same tap, refresh Homebrew metadata and use its standard upgrade command. Review release notes before changing the version used by an existing project.

Verify the CLI

Open a new terminal and confirm that Terraform is available. The displayed version depends on the current release and your installation source.

verify-terraform.sh
terraform version
terraform -help

If the command is not found, inspect PATH and check for multiple Terraform executables. On Windows, use where.exe terraform; on Ubuntu or macOS, use command -v terraform.

Initialize a first project

Create an empty directory, then add the following provider requirement and resource. The version constraint is an example policy; review current provider releases before adopting it.

versions.tf
terraform {
  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "~> 3.0"
    }
  }
}
main.tf
resource "random_pet" "name" {
  length = 2
}

output "generated_name" {
  value = random_pet.name.id
}

Format the files, initialize the working directory, validate the configuration, and inspect the proposed changes.

first-run.sh
terraform fmt
terraform init
terraform validate
terraform plan

Initialization creates a .terraform directory and a dependency lock file. Do not commit the .terraform directory. Commit .terraform.lock.hcl so other runs can select the same provider builds.

Upgrade safely

  • Review Terraform and provider release notes before upgrading.
  • Change one version boundary at a time and test in a branch or non-production environment.
  • Run initialization with controlled upgrade behavior, then review the lock-file change.
  • Run validation and inspect the full plan before applying anything.
  • Keep CI, local development and automation runners on compatible Terraform versions.

Common setup problems

  • Command not found: reopen the shell, correct PATH, and remove stale executable locations.
  • Permission denied: check executable permissions and directory ownership; do not broadly weaken permissions.
  • Provider download failure: verify DNS, proxy, firewall and registry access.
  • Checksum or signature warning: stop and verify the download source; do not bypass trust checks.
  • Wrong architecture: download the package that matches the operating system and CPU.
  • Initialization fails in a reused folder: check configuration, the lock file and previous working-directory state before deleting anything.

Next steps

After the CLI works, learn how provider requirements, authentication and aliases fit into a real configuration.

Terraform providers: configuration, versions and aliases

Official references

Install Terraform

Initialize a Terraform working directory

Dependency lock file

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.