Skip to main content
This guide covers installing Terraform on various operating systems, verifying the installation, and setting up optional features like shell completion. The easiest way to install Terraform is to download a pre-built binary from the HashiCorp Releases website.

Using Homebrew

The recommended way to install Terraform on macOS is using Homebrew:
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
To update Terraform:
brew update
brew upgrade hashicorp/tap/terraform

Manual Installation

  1. Download the appropriate package from the downloads page
  2. Extract the binary:
    unzip terraform_*_darwin_*.zip
    
  3. Move it to a directory in your PATH:
    sudo mv terraform /usr/local/bin/
    
Terraform releases follow semantic versioning. Check the releases page for the latest version.

Building from Source

If you prefer to build Terraform from source, or need a custom build, follow these instructions.

Prerequisites

1

Install Go

Ensure you have Go installed. Terraform requires Go 1.25.7 or later (as specified in .go-version).Download Go from golang.org/dl or use your package manager:
# macOS
brew install [email protected]

# Ubuntu/Debian
sudo apt install golang-1.25

# Fedora
sudo dnf install golang
2

Clone the Repository

Clone the Terraform repository:
git clone https://github.com/hashicorp/terraform.git
cd terraform
3

Build Terraform

Build the binary using the Go toolchain:
go build -o bin/terraform .
This creates a terraform binary in the bin/ directory.

Build Options

Terraform accepts certain options passed using ldflags at build time:

Disable Dev Version Reporting

By default, Terraform includes a -dev flag when reporting its version (e.g., 1.5.0-dev). To disable this:
go build -ldflags "-w -s -X 'github.com/hashicorp/terraform/version.dev=no'" -o bin/terraform .

Enable Experimental Features

Experimental features are disabled by default. To enable them:
go build -ldflags "-w -s -X 'main.experimentsAllowed=yes'" -o bin/terraform .
Experimental features are not recommended for production use. In official builds, experiments are only allowed in alpha releases.

CGO Settings

For most platforms, build with CGO_ENABLED=0 for a statically linked binary:
CGO_ENABLED=0 go build -o bin/terraform .
For macOS/Darwin, use CGO_ENABLED=1 to avoid DNS resolution issues:
CGO_ENABLED=1 go build -o bin/terraform .

Install the Built Binary

After building, move the binary to a directory in your PATH:
# macOS/Linux
sudo mv bin/terraform /usr/local/bin/

# Or add the bin directory to your PATH
export PATH=$PATH:$(pwd)/bin

Verify Installation

After installing Terraform, verify it’s available:
terraform version
You should see output similar to:
Terraform v1.7.0
on linux_amd64
To see all available commands:
terraform -help
Run terraform -help to see a list of all available commands and their descriptions.

System Requirements

Terraform has minimal system requirements:
  • Operating System: macOS, Linux, Windows, or other Unix-like systems
  • Memory: At least 512MB RAM (more recommended for large infrastructures)
  • Disk Space: Approximately 100MB for the binary and plugins
  • Network: Internet access to download providers and modules (unless using air-gapped installations)
Terraform’s memory usage scales with the size and complexity of your infrastructure. Large deployments may require several gigabytes of RAM.

Shell Completion Setup

Terraform supports shell completion for bash, zsh, and fish. This provides tab-completion for commands and options.

Install Shell Completion

Install the completion script:
terraform -install-autocomplete
Then reload your shell:
source ~/.bashrc

Uninstall Shell Completion

To remove shell completion:
terraform -uninstall-autocomplete
The -install-autocomplete command modifies your shell configuration file (.bashrc, .zshrc, etc.) to enable tab completion.

Environment Variables

Terraform supports several environment variables for configuration:
VariableDescription
TF_CLI_ARGSAdditional CLI arguments to append to all commands
TF_DATA_DIROverride the default .terraform directory location
TF_IN_AUTOMATIONSet to any value to suppress prompts (for CI/CD)
TF_LOGEnable logging (values: TRACE, DEBUG, INFO, WARN, ERROR)
TF_LOG_PATHPath to write log output
Example usage:
# Enable debug logging
export TF_LOG=DEBUG
export TF_LOG_PATH=./terraform.log

# Run Terraform
terraform apply

Next Steps

Now that Terraform is installed, you’re ready to start using it:

Quickstart Guide

Create your first infrastructure with Terraform

Core Concepts

Learn about Terraform’s architecture and workflow

Configuration Language

Understand HashiCorp Configuration Language (HCL)

Provider Registry

Browse available providers and modules

Troubleshooting

Command Not Found

If you see command not found: terraform, the binary is not in your PATH:
  1. Verify the binary location: which terraform
  2. Add the directory to your PATH:
    export PATH=$PATH:/path/to/terraform
    
  3. Make the change permanent by adding it to ~/.bashrc, ~/.zshrc, or equivalent

Permission Denied

If you see a permission error when running Terraform:
# Make the binary executable
chmod +x /path/to/terraform

Version Mismatch

If multiple versions of Terraform are installed, use a version manager like tfenv:
# Install tfenv
brew install tfenv

# Install a specific Terraform version
tfenv install 1.7.0
tfenv use 1.7.0
For team environments, consider using .terraform-version files to specify the required Terraform version for each project.

Upgrading Terraform

To upgrade Terraform:
  1. Download the new version using the same method as installation
  2. Replace the old binary with the new one
  3. Run terraform version to verify
Always check the upgrade guides before upgrading between major versions, as there may be breaking changes.
Before upgrading production environments:
  1. Test the new version in a development environment
  2. Review the changelog for breaking changes
  3. Update any deprecated syntax in your configurations
  4. Run terraform plan to verify the upgrade doesn’t cause unexpected changes

Build docs developers (and LLMs) love