How to Upgrade Terraform to a Specific Version Using Brew: Complete Guide
You can upgrade Terraform to a specific version using brew install hashicorp/tap/terraform@X.Y.Z to access the HashiCorp Tap's versioned formulae, or target a historical commit in homebrew-core to install any previous release.
Managing infrastructure with the hashicorp/terraform repository often requires pinning to an exact release for state file compatibility or provider support. While Homebrew's default terraform formula tracks only the latest stable release in Formula/terraform.rb, you can install legacy versions using Homebrew's versioned formula syntax or by installing directly from Git history.
Method 1: Install Using the HashiCorp Homebrew Tap
HashiCorp maintains an official Homebrew Tap that explicitly preserves versioned formulae for side-by-side installation. This method is the most reliable for accessing specific releases without manually searching Git history.
Using Version-Specific Formula Names
The Tap provides versioned formulae using the @ syntax, allowing you to install exact versions:
brew install hashicorp/tap/terraform@1.5.7
This command pulls the formula from hashicorp/homebrew-tap, which maintains historic releases. The formula defines the version "1.5.7" field and constructs the download URL from HashiCorp's releases server automatically.
Method 2: Install from Homebrew Core Historical Commits
The homebrew-core repository stores every iteration of Formula/terraform.rb in its Git history. You can install any previous version by pointing Homebrew to the specific commit where that version was current.
Locate the Target Commit SHA
First, identify the commit in Homebrew/homebrew-core where Formula/terraform.rb contained your desired version. Look for commits where the version field or the url parameter (containing terraform_X.Y.Z_darwin_amd64.zip) matches your target.
Install from the Raw Formula URL
Once you have the commit SHA (e.g., abcdef1234567890abcdef1234567890abcdef12), install using the raw GitHub URL:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/abcdef1234567890abcdef1234567890abcdef12/Formula/terraform.rb
Homebrew downloads the Ruby formula at that exact commit, reads the embedded version string, and fetches the corresponding binary archive from HashiCorp's releases.
Method 3: Switch Between Multiple Installed Versions
If you maintain multiple Terraform versions for different projects, switch between them using Homebrew's link management commands:
# List all installed versions and their paths
brew list --versions terraform
# Remove current version from PATH (keeps files)
brew unlink terraform
# Activate specific version (force required for versioned kegs)
brew link --force terraform@1.5.7
This process modifies symlinks in /usr/local/bin (or /opt/homebrew/bin on Apple Silicon) without re-downloading binaries.
Summary
- Use
hashicorp/tap/terraform@X.Y.Zfor the most straightforward method to install specific versions maintained by HashiCorp. - Target historical commits in
homebrew-coreusing raw GitHub URLs to access any version recorded inFormula/terraform.rbhistory. - Switch versions by unlinking the current formula and linking your target version with
brew link --force. - The installation process relies on the
versionfield within the formula file to construct download URLs pointing to HashiCorp's release archives.
Frequently Asked Questions
Can I install multiple Terraform versions side by side?
Yes. Homebrew installs versioned formulae into separate kegs (directories) based on the formula name. Installing terraform@1.5.7 creates a distinct path from the default terraform formula, allowing you to maintain multiple versions simultaneously and switch using brew unlink and brew link.
How do I find the correct commit SHA for a specific Terraform version?
Search the commit history of Homebrew/homebrew-core for modifications to Formula/terraform.rb. Look for commits where the url line changed to include your target version string (e.g., terraform_1.5.7_darwin_amd64.zip) or where the version field was updated. The commit SHA from that specific change is what you provide in the raw URL installation method.
What is the difference between hashicorp/tap and homebrew/core?
hashicorp/tap is HashiCorp's official Homebrew repository that explicitly maintains versioned formulae (e.g., terraform@1.5.7) for long-term accessibility. homebrew-core is the community-maintained main repository where the terraform formula typically only supports the latest stable release, requiring you to access Git history to install older versions.
How do I verify which Terraform version is currently active?
Execute terraform version in your terminal to display the active binary's version. To see all versions managed by Homebrew, run brew list --versions terraform. If the wrong version executes, ensure you have unlinked the previous version with brew unlink terraform and linked the correct one using brew link --force terraform@X.Y.Z.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s https://instagit.com/install.md