DEV Community

Cover image for Terraform Installation Guide

Terraform Installation Guide

What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to define, provision, and manage infrastructure across various cloud providers using configuration files.

1. Installation Methods (by OS)

Windows

Method 1: Install via Chocolatey (Recommended)

Requires Chocolatey to be installed.

choco install terraform 
Enter fullscreen mode Exit fullscreen mode

Method 2: Manual Installation

  1. Visit the official site: https://www.terraform.io/downloads.html
  2. Download the Windows zip file.
  3. Extract the zip and move terraform.exe to a directory of your choice (e.g., C:\terraform).
  4. Add this directory to your System PATH:
    • Search “Environment Variables” > Edit system environment variables
    • Under System Variables, find Path → Edit → Add C:\terraform
  5. Open a new Command Prompt and verify:
terraform -v 
Enter fullscreen mode Exit fullscreen mode

macOS

Method 1: Using Homebrew (Recommended)

brew tap hashicorp/tap brew install hashicorp/tap/terraform 
Enter fullscreen mode Exit fullscreen mode

Method 2: Manual Installation

  1. Download the macOS zip from https://www.terraform.io/downloads.html
  2. Extract and move terraform to /usr/local/bin:
sudo mv terraform /usr/local/bin/ 
Enter fullscreen mode Exit fullscreen mode
  1. Verify the installation:
terraform -v 
Enter fullscreen mode Exit fullscreen mode

Linux (Ubuntu/Debian-based)

Method 1: Official HashiCorp APT Repo

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \ https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \ sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update sudo apt install terraform 
Enter fullscreen mode Exit fullscreen mode

Method 2: Manual Installation

  1. Download the Linux zip from https://www.terraform.io/downloads.html
  2. Unzip and move binary:
unzip terraform_*.zip sudo mv terraform /usr/local/bin/ 
Enter fullscreen mode Exit fullscreen mode
  1. Verify:
terraform -v 
Enter fullscreen mode Exit fullscreen mode

2. Verifying Installation

After installation, run:

terraform version 
Enter fullscreen mode Exit fullscreen mode

Output should be like:

Terraform v.... on linux_amd64 
Enter fullscreen mode Exit fullscreen mode

3. Updating Terraform

Using Homebrew (macOS)

brew upgrade terraform 
Enter fullscreen mode Exit fullscreen mode

Using Chocolatey (Windows)

choco upgrade terraform 
Enter fullscreen mode Exit fullscreen mode

Using APT (Linux)

sudo apt update && sudo apt install terraform 
Enter fullscreen mode Exit fullscreen mode

Common Troubleshooting

Problem Fix
terraform: command not found Ensure terraform binary is in your PATH
Terraform version shows as outdated Run update via package manager
Error downloading providers Check internet connection or proxy issues
File permission denied (Linux/macOS) Use chmod +x terraform and sudo if needed

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.