Install Terraform: CLI Setup Guide for Linux, macOS & Windows
In this tutorial, you'll learn about Install Terraform: CLI Setup Guide for Linux, macOS & Windows. We cover key concepts, practical examples, and best practices.
Installing Terraform is the first step toward managing cloud infrastructure as code, requiring only a binary download or a package manager command to get started on any major operating system.
What You'll Learn
In this tutorial, you will learn how to install Terraform on Linux, macOS, and Windows, verify the installation, configure your first provider, and initialize a working directory.
Why It Matters
A correct installation ensures you have the right version, access to all subcommands, and proper integration with your cloud providers. An incorrectly installed Terraform leads to cryptic errors, missing features, and wasted debugging time.
Real-World Use
Every Terraform user, from solo developers at startups to platform engineering teams at enterprises like Durga Antivirus Pro, starts with installation. The same install process applies whether you are managing three EC2 instances or three thousand.
System Requirements
Terraform is a single binary with no external dependencies. It runs on Linux (amd64, arm64), macOS (amd64, arm64), and Windows (amd64). You need 100 MB of free disk space and appropriate permissions to install software.
Install on Linux
Using apt (Ubuntu, Debian)
wget -O- 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
Expected output: The terraform binary installs to /usr/bin/<a href="/devops/terraform/">terraform</a> and is ready to use.
Using yum (Amazon Linux, RHEL)
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Expected output: Terraform installs via RPM and becomes available system-wide.
Manual Installation (any Linux)
wget https://releases.hashicorp.com/terraform/1.9.0/terraform_1.9.0_linux_amd64.zip
unzip terraform_1.9.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform --version
Expected output:
Terraform v1.9.0
on linux_amd64
Install on macOS
Using Homebrew
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Expected output: Homebrew downloads, verifies, and installs Terraform to /opt/homebrew/bin/<a href="/devops/terraform/">terraform</a> (Apple Silicon) or /usr/local/bin/<a href="/devops/terraform/">terraform</a> (Intel).
Manual Installation (macOS)
curl -LO https://releases.hashicorp.com/terraform/1.9.0/terraform_1.9.0_darwin_amd64.zip
unzip terraform_1.9.0_darwin_amd64.zip
sudo mv terraform /usr/local/bin/
Expected output: The binary is placed in /usr/local/bin and accessible from any terminal.
Install on Windows
Using Chocolatey:
choco install terraform
Using Winget:
winget install HashiCorp.Terraform
Expected output: Terraform is added to the system PATH and available in PowerShell or CMD.
Verify the Installation
terraform --version
Expected output:
Terraform v1.9.0
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.0.0
Run <a href="/devops/terraform/">terraform</a> -help to see all available commands. The help output lists init, plan, apply, destroy, validate, fmt, and more.
Configure Autocomplete
terraform -install-autocomplete
Expected output: Adds Terraform command completion to your shell. Open a new terminal and type <a href="/devops/terraform/">terraform</a> then press Tab to see available subcommands.
Common Mistakes
1. Installing an Incompatible Version
Using a version older than 1.0 loses access to features like <a href="/devops/terraform/">terraform</a> test. Always install the latest stable version.
2. Missing System PATH
After manual installation, the terraform binary must be in a directory listed in your PATH variable. Verify with which <a href="/devops/terraform/">terraform</a>.
3. Mixing Package Managers
Using both Homebrew and manual installation causes version conflicts. Choose one method and stick with it.
4. Installing Without GPG Verification
Skipping GPG key verification when using apt or yum leaves you vulnerable to compromised packages. Always verify HashiCorp's signing key.
5. Ignoring Architecture
Downloading the amd64 binary for an arm64 system (Apple Silicon or AWS Graviton) will fail. Always select the correct architecture.
Practice Questions
1. What is the recommended way to install Terraform on Ubuntu?
Add the HashiCorp apt repository, import the GPG key, and run sudo apt install <a href="/devops/terraform/">terraform</a>.
2. How do you verify Terraform installed correctly?
Run <a href="/devops/terraform/">terraform</a> --version to check the version and available providers.
3. What command enables shell autocomplete for Terraform?
<a href="/devops/terraform/">terraform</a> -install-autocomplete adds completion to your shell configuration.
4. Why should you avoid mixing installation methods? Using both a package manager and manual install creates version conflicts and makes upgrades inconsistent.
5. Challenge: Install Terraform using the manual method, add autocomplete, and run <a href="/devops/terraform/">terraform</a> -help to verify twenty-six available commands.
Mini Project: First Workspace Initialization
Create a directory called learn-<a href="/devops/terraform/">terraform</a>, write an empty main.tf file with <a href="/devops/terraform/">terraform</a> {} block, run <a href="/devops/terraform/">terraform</a> init, and observe the .<a href="/devops/terraform/">terraform</a> directory and .<a href="/devops/terraform/">terraform</a>.lock.hcl file created by the initialization process.
Related Concepts
What's Next
Now that Terraform is installed, learn HCL Syntax to understand the configuration language, then explore Providers to connect to your cloud platform.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro