Here is how to install Terraform on Ubuntu 24.04 LTS. Tested and verified.
Prerequisites
- Ubuntu 24.04 LTS installed and updated
- Root or sudo access
- Internet connection
Step 1: Update System
sudo apt update && sudo apt upgrade -yStep 2: Add Official Repository
Terraform is distributed through HashiCorpβs official apt repository. Import the signing key and register the repository before installing:
# Install prerequisites for adding a signed apt repository
sudo apt install -y wget gnupg
# Import the HashiCorp GPG signing key
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Add the official HashiCorp repository (resolves to "noble" on Ubuntu 24.04)
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt updateStep 3: Install Terraform
sudo apt install -y terraformStep 4: Verify Installation
terraform versionExpected output should show the installed version, for example Terraform v1.x.x.
Step 5: Enable Shell Autocomplete
Terraform is a CLI binary with no background service, so there is nothing to enable or start with systemd. Instead, enable tab-completion for your shell:
terraform -install-autocompleteThis appends the completion hook to your shell profile (~/.bashrc for Bash). Restart your shell or run source ~/.bashrc for it to take effect.
Troubleshooting
GPG Key Import Failure
If apt update reports NO_PUBKEY or a signature verification error, the keyring file may be missing or empty. Re-run the key import and confirm the file exists:
ls -l /usr/share/keyrings/hashicorp-archive-keyring.gpg
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
sudo apt updatePackage Not Found
Confirm the repository was registered and refresh the apt cache:
cat /etc/apt/sources.list.d/hashicorp.list
sudo apt update
apt-cache policy terraformIf apt-cache policy terraform shows no install candidate, double-check that the codename in hashicorp.list matches Ubuntu 24.04βs codename (noble).
Uninstall
sudo apt remove -y terraformRelated Guides
About the Author
I am Luca Berton, AI and Cloud Advisor. Book a consultation to get help with your infrastructure setup.