Terraform is a popular Infrastructure as Code (IaC) tool from HashiCorp that lets you provision and manage cloud resources using a declarative configuration language (HCL). This guide installs Terraform on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A user with sudo privileges
- A cloud provider account (AWS, GCP, Azure, etc.)
Step 1 – Add the HashiCorp Repository
Add the HashiCorp GPG key and apt repository:
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
Step 2 – Install Terraform
Install:
sudo apt update
sudo apt install terraform -y
Step 3 – Verify the Installation
Check the version:
terraform --version
Step 4 – Create a Terraform Project
Create a project directory and configuration file:
mkdir ~/terraform-project && cd ~/terraform-project
nano main.tf
Add a simple local file resource:
terraform {
required_version = ">= 1.0"
}
resource "local_file" "hello" {
content = "Hello from Terraform on Ubuntu 24.04!"
filename = "/tmp/terraform-hello.txt"
}
Step 5 – Initialise, Plan, and Apply
Run the Terraform workflow:
terraform init
terraform plan
terraform apply
Step 6 – Inspect and Destroy
View the state and destroy resources:
terraform show
terraform state list
terraform destroy
Step 7 – Enable Tab Completion
Add autocomplete to your shell:
terraform -install-autocomplete
source ~/.bashrc
Conclusion
Terraform is installed on Ubuntu 24.04 LTS. Use providers for AWS, Azure, GCP, or Kubernetes to provision real cloud infrastructure. Store state files in S3 or Terraform Cloud for team use.