Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It allows you to define and manage your infrastructure using declarative configuration files. In this guide, we’ll walk you through the installation process for Terraform on Linux, macOS, and Windows.
Prerequisites
Before you begin, ensure that you have the following prerequisites:
- Operating System: Make sure you have a supported operating system. Terraform supports Linux, macOS, and Windows.
- Internet Connection:** You’ll need an active internet connection to download Terraform.
Install Terraform on Linux
Follow these steps to install Terraform on Linux:
Ensure that your system is up to date and you have installed the gnupg
, software-properties-common
, and curl
packages installed.
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
Install the HashiCorp GPG key
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
Verify the key’s fingerprint.
gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint
The gpg
command will report the key fingerprint:
/usr/share/keyrings/hashicorp-archive-keyring.gpg ------------------------------------------------- pub rsa4096 XXXX-XX-XX [SC] AAAA AAAA AAAA AAAA uid [ unknown] HashiCorp Security (HashiCorp Package Signing) <[email protected]> sub rsa4096 XXXX-XX-XX [E]
Refer to the Official Packaging Guide for the latest public signing key. You can also verify the key on Security at HashiCorp under Linux Package Checksum Verification.
Add the official HashiCorp repository to your system.
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
Update all packages
sudo apt update
Install Terraform from the new repository.
sudo apt-get install terraform
Install Terraform on MacOS
Ensure you have Homebrew installed on your system.
Homebrew: Homebrew is a popular package manager for macOS. If you don’t have it installed, visit https://brew.sh/ for installation instructions.
First, install the HashiCorp tap, a repository of all our Homebrew packages.
brew tap hashicorp/tap
Now, install Terraform with hashicorp/tap/terraform
.
brew install hashicorp/tap/terraform
This installs a signed binary and is automatically updated with every new official release.
To update to the latest version of Terraform, first update Homebrew.
brew update
Then, run the upgrade
command to download and use the latest Terraform version.
brew upgrade hashicorp/tap/terraform ==> Upgrading 1 outdated package: hashicorp/tap/terraform 0.15.3 -> 1.0.0 ==> Upgrading hashicorp/tap/terraform 0.15.3 -> 1.0.0
Install Terraform on Windows ( Chocolatey)
Chocolatey is a free and open-source package management system for Windows. Install the Terraform package from the command-line.
choco install terraform
Chocolatey and the Terraform package are NOT directly maintained by HashiCorp. The latest version of Terraform is always available by manual installation.