How to Install Terraform

This document will introduce how to install Terraform on different operating systems.

Pre-installation Preparation

Before installing Terraform, please ensure your system meets the following requirements:

  • 64-bit operating system

  • Supported operating systems: Linux, Windows, MacOS

  • Network connection (for downloading installation packages)

Linux System Installation

Ubuntu/Debian System

  1. Update system package index

    sudo apt-get update
    sudo apt-get install -y gnupg software-properties-common curl
  2. Add HashiCorp GPG key

    wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
  3. Add official HashiCorp Linux repository

    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
  4. Update and install

    sudo apt update
    sudo apt install terraform

CentOS/RHEL System

  1. Install yum-config-manager

  2. Add HashiCorp repository

  3. Install Terraform

Windows System Installation

  1. Install Chocolatey (if not already installed)

  2. Install Terraform using Chocolatey

Method 2: Manual Installation

  1. Download the Windows version zip file

  2. Extract the file to a specified directory (e.g., C:\terraform)

  3. Add this directory to the system environment variable Path:

    • Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables"

    • Find "Path" in "System Variables"

    • Click "Edit" → "New"

    • Add the Terraform directory path (e.g., C:\terraform)

    • Click "OK" to save settings

MacOS System Installation

  1. Install Homebrew (if not already installed)

  2. Install Terraform

Method 2: Manual Installation

  1. Download the MacOS version zip file

  2. Extract the file

  3. Move the terraform binary to system path:

Verify Installation

After installation, please verify that Terraform is correctly installed:

If installation is successful, you will see output similar to:

Post-installation Configuration

1. Configure Command Line Auto-completion (Optional)

For Bash users:

2. Verify Installation Environment

Create a test directory and initialize:

Reference Information

Last updated