What is the Terraform CLI?
Terraform is beautifully simple on the surface. It is distributed as a single, standalone binary file.
You do not need to install complex language runtimes (like Python, Node.js, or Java). You just download the executable, put it in your system's PATH, and you are ready to manage infrastructure.
Installing on MacOS
The easiest way to install Terraform on a Mac is using Homebrew.
-
First, install the official HashiCorp tap (repository):
brew tap hashicorp/tap -
Then, install the terraform package:
brew install hashicorp/tap/terraform -
To update Terraform in the future, simply run:
brew upgrade hashicorp/tap/terraform
Installing on Windows
On Windows, the easiest method is using the Chocolatey package manager.
- Open a terminal (PowerShell or Command Prompt) as Administrator.
- Run the Chocolatey install command:
choco install terraform
Alternative: If you prefer Winget, you can run:
winget install Hashicorp.TerraformInstalling on Linux (Ubuntu/Debian)
For Linux, you add the official HashiCorp repository to your system's package manager.
-
Install prerequisite packages:
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 > /dev/null -
Add the 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 -
Update and install:
sudo apt update sudo apt-get install terraform
Verifying the Installation
Regardless of your operating system, verify the installation by opening a new terminal window and running:
terraform -versionYou should see output similar to this:
Terraform v1.7.0
on darwin_amd64
If your terminal says command not found: terraform, ensure that the directory containing the Terraform executable is included in your system's PATH environment variable.
Setting Up Your IDE (Crucial!)
While you could write Terraform (.tf) files in Notepad, you absolutely shouldn't. Using a proper IDE will catch syntax errors instantly, provide auto-completion for cloud resources, and automatically format your code.
We highly recommend Visual Studio Code (VS Code).
The Official HashiCorp Extension
- Open VS Code.
- Go to the Extensions tab (
Ctrl+Shift+XorCmd+Shift+X). - Search for "HashiCorp Terraform".
- Install the official extension published by HashiCorp.
What the extension provides:
- Syntax Highlighting: Makes HCL code beautiful and readable.
- IntelliSense/Auto-completion: Start typing
aws_and it will suggestaws_instance,aws_vpc, etc., along with all their required arguments! - Linting & Validation: Red squiggly lines instantly show you where you made a typo or missed a required parameter.
- Format on Save: It can automatically run
terraform fmtevery time you save, ensuring your code always meets team style standards.
To enable Format on Save for Terraform files in VS Code, open your settings (Ctrl+,), search for "format on save", and check the box.
Enable Tab Autocompletion in Terminal
If you use Bash or Zsh, Terraform can magically auto-complete its own CLI commands (e.g., typing terraform a and pressing Tab will complete it to terraform apply).
To install the autocomplete package:
terraform -install-autocompleteYou will need to restart your terminal for the changes to take effect.