TerraformPilot

Terraform

Install Terraform on WSL (Windows Subsystem for Linux)

Install Terraform on Windows Subsystem for Linux (WSL). Ubuntu, Debian, and RHEL on WSL2 with AWS CLI, VS Code integration, and path configuration.

LLuca Berton1 min read

Quick Answer

#
# Inside WSL (Ubuntu)
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
terraform version

Prerequisites: Install WSL2

#
# In PowerShell (Admin)
wsl --install
# Restart, then set up Ubuntu username/password

Method 1: Official APT Repository (Ubuntu WSL)

#
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
 
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
terraform -install-autocomplete

Method 2: Binary Download

#
TERRAFORM_VERSION="1.8.5"
wget "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
sudo mv terraform /usr/local/bin/
rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"

AWS CLI Setup in WSL

#
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws configure

VS Code Integration

#
# Install VS Code on Windows, then from WSL:
code .
# Opens VS Code connected to WSL filesystem

Install these VS Code extensions:

  • HashiCorp Terraform — syntax highlighting, completion
  • Remote - WSL — seamless WSL integration

WSL Tips for Terraform

#
# Store Terraform projects in WSL filesystem (faster I/O)
mkdir -p ~/projects/terraform
cd ~/projects/terraform
 
# DON'T use /mnt/c/ for Terraform projects — very slow file I/O
 
# Git line endings (prevent CRLF issues)
git config --global core.autocrlf input
#

Conclusion

#

WSL2 gives you a native Linux Terraform experience on Windows. Use the official HashiCorp APT repository, store projects in the WSL filesystem (not /mnt/c/), and connect VS Code with the Remote WSL extension. Avoid Windows-native Terraform if you're using WSL — stick to the Linux binary.

#Terraform#Windows#WSL#Linux#Install

Share this article