Terraform for macOS: Complete Installation and Configuration Guide

Terraform is an open-source Infrastructure as Code IaC tool that enables infrastructure management and provisioning. The tool is extremely popular with DevOps teams because it allows them to define resources in configuration files to automate infrastructure provisioning across different providers. Terraform lets you safely and consistently manage your infrastructure as code across multiple cloud providers. To provision infrastructure with Terraform, you will write configuration in Terraform's configuration language, configure your cloud provider credentials, and apply your configuration with the Terraform Command Line Interface CLI.

HashiCorp distributes Terraform as an executable CLI that you can install on supported operating systems, including Microsoft Windows, macOS, and several Linux distributions. You can also compile the Terraform CLI from source if a pre-compiled binary is not available for your system.

If you use a package manager to install software on your macOS, Windows, or Linux system, you can use it to install Terraform. Homebrew is a free and open-source package management system for macOS. If you have Homebrew installed, use it to install Terraform from your command line.

Prerequisites

Before installing Terraform on macOS, confirm the following requirements are met.

A user account with admin or root privileges is required. Command-line access is needed for all installation methods. For manual zip installations, curl is required on macOS. For Linux style prerequisites, wget and unzip are mentioned for Linux environments.

Terraform CLI ships as a single Go binary, so the bar to run it is low. HashiCorp distributes Terraform as a binary package. You can also install Terraform using popular package managers.

Installation Methods Overview

macOS supports multiple installation paths for Terraform. The choice depends on automation needs, version pinning requirements, and system preferences.

Method Package Manager Best For Maintenance
Homebrew via hashicorp tap Homebrew Latest stable release, easy updates HashiCorp maintained
Manual zip archive with curl None Custom path control, offline installs Manual
Direct binary copy to /opt None System-wide installation Manual

Homebrew installs the latest stable version of Terraform from the HashiCorp tap. HashiCorp maintains an official Homebrew tap with all their tools. Terraform, Vault, Packer, Consul, etc. The hashicorp/tap/terraform formula is maintained by HashiCorp and always has the latest release. The default terraform formula in homebrew-core may lag behind.

Install Terraform on macOS Using Homebrew

Homebrew is the most common method for macOS users. HashiCorp maintains an official Homebrew tap with all their tools.

First, install the HashiCorp tap, which is Hashicorp's official repository of all our Homebrew packages.

bash brew tap hashicorp/tap

Now, install Terraform from hashicorp/tap/terraform.

bash brew install hashicorp/tap/terraform

Expected output confirms installation. If you see the version number, Terraform is installed correctly.

Verification step:

bash terraform --version

Output on Apple Silicon M1/M2/M3/M4 can show architecture specific details.

Terraform supports tab-completion for commands and arguments. Then restart your shell or run source ~/.zshrc. Now you can type terraform pl + Tab → terraform plan.

If your team requires a specific version, version pinning can be handled via tfenv. Important: If you already have Terraform installed via Homebrew, unlink it first before using tfenv.

Homebrew verification can be checked with:

bash brew --version

HashiCorp regularly releases new versions of Terraform with new features and bug fixes.

Install Terraform on macOS Using Zip Archive

Installing Terraform on macOS is possible from a zipped file containing the Terraform binary, or via the official HashiCorp repository. The repository contains other non-Terraform HashiCorp products you can install later.

The steps to install Terraform on macOS from the downloaded zip archive are similar to those for Linux systems. Instead of wget, use curl on macOS.

  1. Browse to the Download Terraform page.
  2. Select the macOS tab under the Operating System heading. The latest version is preselected.
  3. Right-click the Download button for your system's architecture and copy the download link. In our case, it is ARM64.
  4. Use curl to download the file from the link you copied in the previous step:

bash curl https://releases.hashicorp.com/terraform/1.9.2/terraform_1.9.2_darwin_arm64.zip -O

  1. Find a user directory in PATH to put the Terraform binary in it:

bash echo $PATH

In our case, we will use the /usr/local/bin directory.

  1. Use the full file name with the extension when extracting the archive. Make sure to use the correct name for your architecture and the version you downloaded.

Alternative manual path installation:

Log in to the system and create a folder for the Terraform executable:

bash sudo mkdir -p /opt/terraform

Navigate to the new folder:

bash cd /opt/terraform

From the Terraform downloads website, copy the macOS Terraform zip file download link:

Download the zip file in the previously created folder:

bash sudo curl -O <copied_url>

Unzip the Terraform files in the current folder:

bash sudo unzip <zip_file_name>

The unzipped files will be in the current folder.

Next, add Terraform to the PATH. Navigate to the home folder and execute this command to open and edit the bash profile:

bash sudo vi ~/.bash_profile

Add these two lines to the opened file:

PATH="/opt/terraform:${PATH}" export PATH

Execute the file for the path changes to take effect:

bash source ~/.bash_profile

Now that Terraform is installed, verify the Terraform version by running:

bash terraform –version

This should show the Terraform version that is installed in the system.

That completes your installation of Terraform on macOS.

Verify Installation and Basic Commands

Verification is performed after installation.

bash terraform --version

Example output:

Terraform v1.3.7 on darwin_arm64

Basic workflow commands:

Initialize Terraform before using it.

bash terraform init

Output:

Terraform initialized in an empty directory!

Check the status of Terraform. To check the current status of your infrastructure resources, use the following command. With no configuration, an error is returned.

bash terraform plan

Error:

│ Error: No configuration files

Apply Terraform to make changes to the infrastructure.

bash terraform apply

Error with no configuration:

│ Error: No configuration files

Deleting Terraform infrastructure resource.

bash terraform destroy

Managing Terraform Status. You can use the following commands to check and manage your current state.

bash terraform state

Version Management and Multiple Versions

Many teams run different Terraform versions per project. tfenv is a version manager like nvm for Node.js.

Create a .terraform-version file in your project root:

bash echo "1.12.0" > .terraform-version

tfenv automatically switches when you cd into the directory.

To unpin later:

bash tfenv use system

If you prefer not to use Homebrew, manual zip installation provides full control.

Your shell can't find the binary if PATH is not updated correctly.

Troubleshooting Common Errors

Homebrew installation can fail due to missing developer tools.

Error encountered during installation:

Error: No developer tools installed. Install the Command Line Tools: xcode-select --install

Fix:

bash xcode-select --install

Second error:

Error: 'git' must be installed and in your PATH!

Fix:

bash brew install git

After installing xcode and git, Terraform can install completely.

Common PATH issues after manual installation occur when the binary is placed outside a directory listed in PATH. Use echo $PATH to verify location and update ~/.bash_profile or ~/.zshrc accordingly.

Verification step for installation by verifying the version:

bash terraform -version

To verify that the latest Terraform version is installed, run the terraform -version command.

Conclusion

Installing Terraform on macOS is straightforward with either Homebrew or a manual zip archive. Homebrew via hashicorp/tap/terraform provides the simplest path to a maintained, up-to-date CLI with tab completion and automatic updates. Manual installation via curl and unzip gives precise control over binary location and system-wide placement in directories such as /opt/terraform or /usr/local/bin.

Both methods require verifying the installation with terraform --version and ensuring developer tools and git are present for Homebrew operations. Once installed, the core workflow of terraform init, terraform plan, terraform apply, terraform destroy, and terraform state enables safe infrastructure management as code. Version managers like tfenv allow teams to pin and switch versions per project, while PATH configuration ensures the binary remains accessible across shells.

For macOS users, maintaining the HashiCorp tap, keeping Xcode command line tools current, and verifying PATH after manual installs prevents the most common errors and keeps Terraform ready for production workflows.

Sources

  1. PhoenixNAP
  2. Spacelift
  3. HashiCorp Developer
  4. dev.to
  5. Terraform Pilot

Related Posts