Terraform 2: Installing Terraform + the CLI
easy⏱ 5 mincourseterraform
One binary, on your PATH
Terraform ships as a single executable — no runtime to install. On macOS use Homebrew; on Windows use winget/Chocolatey; on Linux download the zip or use the HashiCorp apt repo. After installing, verify with terraform -version.
# macOS (Homebrew)
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
# Windows (winget)
winget install HashiCorp.Terraform
# Verify the install
terraform -version
# => Terraform v1.9.5
# => on darwin_arm64
Pin the version with tfenv
Teams pin an exact Terraform version so everyone runs the same one. tfenv manages multiple versions; a .terraform-version file in the repo makes tfenv auto-select. This avoids state-format surprises when a teammate is on a newer CLI.
# Install and pin a version per-repo
tfenv install 1.9.5
tfenv use 1.9.5
# .terraform-version (committed to the repo)
1.9.5
required_version enforces it in code
Beyond tooling, pin the version inside the config with a terraform { required_version = ... } block. If a CLI outside the range runs init, Terraform refuses — a guardrail that lives in the repo, not on someone's laptop.
terraform {
required_version = ">= 1.9.0, < 2.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.100"
}
}
}
Parse a version string
Write parseTerraformVersion(output: string): string that extracts the semantic version (e.g. 1.9.5) from a line like Terraform v1.9.5. Call it on the sample and log the result.