TerraformPilot

Terraform

How to Install Terraform on Windows WSL2 - Complete Step-by-Step Guide

Step-by-step guide to install Terraform on Windows WSL2. Install HashiCorp Terraform using apt, verify the installation, and configure your first project.

LLuca Berton2 min read

Introduction

#

Terraform is the industry-standard Infrastructure as Code (IaC) tool for provisioning and managing cloud resources. This guide shows you how to install Terraform on Windows WSL2 in under 5 minutes.

What is WSL2?

#

Windows Subsystem for Linux 2 (WSL2) lets you run a full Linux environment directly on Windows without dual-booting. It's the recommended way to use Terraform on Windows for a native Linux experience.

Install WSL2 First

#

If you haven't installed WSL2 yet:

# Run in PowerShell as Administrator
wsl --install -d Ubuntu-24.04

Restart your computer, then open Ubuntu from the Start menu to complete setup.

Prerequisites

#
  • A Windows WSL2 system (with WSL2 enabled)
  • Root or sudo access
  • An active internet connection

Install Terraform on Windows WSL2

#
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 noble main" | \
  sudo tee /etc/apt/sources.list.d/hashicorp.list
 
sudo apt-get update && sudo apt-get install terraform

Verify the Installation

#
terraform -version

Expected output:

Terraform v1.12.x
on linux_amd64

Enable Tab Completion

#
terraform -install-autocomplete
source ~/.bashrc

Alternative: Install from Binary

#
TERRAFORM_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | grep -oP '"current_version":"\K[^"]+')
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/
terraform -version

Alternative: Install with tfenv

#
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
tfenv install latest
tfenv use latest

Your First Terraform Project

#
mkdir ~/terraform-demo && cd ~/terraform-demo
cat > main.tf << 'EOF'
terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "~> 2.0"
    }
  }
}
 
resource "local_file" "hello" {
  content  = "Hello from Terraform on Windows WSL2!"
  filename = "${path.module}/hello.txt"
}
EOF
 
terraform init
terraform apply -auto-approve
cat hello.txt

Upgrade Terraform

#
sudo apt-get update && sudo apt-get upgrade terraform

Uninstall Terraform

#
sudo apt-get remove terraform

Next Steps

#

Install Terraform on other platforms:

#Terraform#Windows (WSL2)#Installation

Share this article