TerraformPilot

DevOps

Install Terraform on Debian: Step-by-Step Guide

Install Terraform on Debian 12 Bookworm using the HashiCorp APT repository or manual binary download. Includes verification, autocomplete setup

LLuca Berton1 min read

Debian doesn't include Terraform in its default repositories. You need to add the HashiCorp APT repository or download the binary manually. Both methods work on Debian 12 (Bookworm), 11 (Bullseye), and newer.

#
# Install prerequisites
sudo apt-get update
sudo apt-get install -y gnupg software-properties-common curl
 
# Add HashiCorp GPG key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
 
# Add 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
 
# Install Terraform
sudo apt-get update
sudo apt-get install -y terraform
 
# Verify
terraform version
# Terraform v1.10.0

Method 2: Manual Binary Download

#
# Download
TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
 
# Install unzip if needed
sudo apt-get install -y unzip
 
# Extract and install
unzip terraform.zip
sudo mv terraform /usr/local/bin/
rm terraform.zip
 
# Verify
terraform version

ARM64 (Raspberry Pi, ARM servers)

#
TERRAFORM_VERSION="1.10.0"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/

Verify GPG Signature (Optional)

#
TERRAFORM_VERSION="1.10.0"
 
# Download binary + SHA256 sums + signature
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS" -o SHA256SUMS
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.sig" -o SHA256SUMS.sig
 
# Import HashiCorp GPG key
curl -fsSL https://www.hashicorp.com/.well-known/pgp-key.txt | gpg --import
 
# Verify signature
gpg --verify SHA256SUMS.sig SHA256SUMS
 
# Verify checksum
sha256sum -c SHA256SUMS --ignore-missing
# terraform_1.10.0_linux_amd64.zip: OK

Enable Autocomplete

#
terraform -install-autocomplete
source ~/.bashrc
 
# Test: terraform pl<TAB> → terraform plan

Docker (Debian Base)

#
FROM debian:bookworm-slim
 
RUN apt-get update && \
    apt-get install -y gnupg curl lsb-release && \
    curl -fsSL https://apt.releases.hashicorp.com/gpg | 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" > /etc/apt/sources.list.d/hashicorp.list && \
    apt-get update && \
    apt-get install -y terraform && \
    apt-get clean && rm -rf /var/lib/apt/lists/*
 
ENTRYPOINT ["terraform"]

Update Terraform

#
# APT repository — standard apt upgrade
sudo apt-get update
sudo apt-get install --only-upgrade terraform
 
# Manual — download new version
TERRAFORM_VERSION="1.10.1"
curl -fsSL "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -o terraform.zip
unzip terraform.zip
sudo mv terraform /usr/local/bin/

Uninstall

#
# APT method
sudo apt-get remove terraform
 
# Manual method
sudo rm /usr/local/bin/terraform

Quick Test

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

Troubleshooting

#

"lsb_release: command not found"

#
sudo apt-get install -y lsb-release

Or hardcode the codename:

# Debian 12
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com bookworm main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

"gpg: no valid OpenPGP data found"

#
# Re-download the key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

"Permission denied" on /usr/local/bin

#
sudo mv terraform /usr/local/bin/
sudo chmod +x /usr/local/bin/terraform

Hands-On Courses

#

Conclusion

#

The HashiCorp APT repository is the easiest way to install Terraform on Debian — one-time setup, then apt-get install terraform with automatic updates. For airgapped or minimal systems, download the binary directly. Both methods take under 2 minutes.

#Terraform#DevOps#Installation#Debian#Linux

Share this article