Introduction
Terraform is a powerful open-source tool created by HashiCorp that allows you to define, provision, and manage infrastructure as code. This article provides a detailed guide on installing Terraform on Ubuntu Linux, ensuring you can manage your infrastructure effectively.
Ubuntu, known for its ease of use and robustness, is a popular choice for many developers and sysadmins. Pairing it with Terraform enhances your ability to manage infrastructure seamlessly. This guide focuses on installing Terraform version 1.7.2 on Ubuntu Linux.
Prerequisites
- Ubuntu Linux system
- Internet connectivity
- Sudo privileges
Installation Steps
1. Update and Install Dependencies
Before proceeding, update your package lists to ensure you have the latest versions available:
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
2. Add HashiCorp GPG Key
HashiCorp signs their packages with a GPG key. Add it to your system:
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
Verify the fingerprint for added security:
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
3. Add HashiCorp Repository
Next, add the HashiCorp repository to your system:
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
4. Update Package Lists
After adding the new repository, update your package lists again:
sudo apt update
Output:
Hit:1 http://ports.ubuntu.com/ubuntu-ports mantic InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports mantic-updates InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports mantic-backports InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports mantic-security InRelease
Get:5 https://apt.releases.hashicorp.com mantic InRelease [9,523 B]
Get:6 https://apt.releases.hashicorp.com mantic/main arm64 Packages [4,413 B]
Fetched 13.9 kB in 1s (18.7 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
5. Install Terraform
Now, you can install Terraform:
sudo apt install terraform
Output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
terraform
0 upgraded, 1 newly installed, 0 to remove and 45 not upgraded.
Need to get 24.4 MB of archives.
After this operation, 80.5 MB of additional disk space will be used.
Get:1 https://apt.releases.hashicorp.com mantic/main arm64 terraform arm64 1.7.2-1 [24.4 MB]
Fetched 24.4 MB in 13s (1,943 kB/s)
Selecting previously unselected package terraform.
(Reading database ... 101523 files and directories currently installed.)
Preparing to unpack .../terraform_1.7.2-1_arm64.deb ...
Unpacking terraform (1.7.2-1) ...
Setting up terraform (1.7.2-1) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
6. Verify Terraform Installation
To ensure Terraform is installed correctly:
terraform --version
This command should show the installed version of Terraform.
Terraform v1.7.2
on linux_arm64
7. Enable Terraform Autocomplete (Optional)
For an enhanced command-line experience, enable the autocomplete feature:
terraform -install-autocomplete
Restart your shell to activate the autocomplete functionality.
Conclusion
You have now successfully installed Terraform on Ubuntu Linux. This setup will allow you to efficiently manage and automate your infrastructure. Regularly check for Terraform updates and explore its vast documentation to fully leverage its capabilities in your DevOps workflow.