How to Install Terraform on Ubuntu 24.04 Linux

Terraform is a powerful open-source infrastructure-as-code software tool created by HashiCorp. It allows users to define and provision data center infrastructure using a high-level configuration language. Whether you’re managing a small application environment or deploying enterprise-grade infrastructure, Terraform is a go-to tool for DevOps professionals. Installing Terraform on Ubuntu 24.04 Linux is a straightforward process, and this guide will walk through each step in detail.

Prerequisites

Before installing Terraform, ensure the system is updated and has the necessary tools installed. It’s recommended to have sudo privileges and access to a terminal or SSH session.

  • An Ubuntu 24.04 system
  • Sudo privileges
  • Internet connection to download packages

Step 1: Update the System

Begin by updating the package list and installed packages to the latest versions:

sudo apt update && sudo apt upgrade -y

Step 2: Install Required Dependencies

Use the following command to install utilities such as gnupg, software-properties-common, and curl:

sudo apt install -y gnupg software-properties-common curl

Step 3: Add the HashiCorp GPG Key

Before installing Terraform, the system must trust HashiCorp’s packages. Add the HashiCorp GPG key with this command:

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

Step 4: Add the HashiCorp Linux Repository

After importing the GPG key, 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

Update the package list again to include the new repository:

sudo apt update

Step 5: Install Terraform

Now, install Terraform using the APT package manager:

sudo apt install terraform

Once installation is complete, check the installed version to confirm that it’s working:

terraform -v

Step 6: Verify and Test

To ensure Terraform installed correctly and is ready to use, initialize a simple directory and validate the setup:


mkdir terraform-test
cd terraform-test
terraform init

If the output includes “Terraform has been successfully initialized”, the setup is confirmed.

Optional: Enable Terraform Autocompletion

Terraform supports shell autocompletion for improved efficiency. To enable Bash autocompletion, run:

terraform -install-autocomplete

Restart the terminal or run source ~/.bashrc to apply the changes.

Conclusion

Installing Terraform on Ubuntu 24.04 is a smooth process when following the correct steps. With Terraform installed, users can begin automating infrastructure deployment for multiple cloud providers including AWS, Azure, and Google Cloud. This installation gives developers and system administrators a robust toolset to manage resources more effectively through code.

Frequently Asked Questions (FAQ)

  • Q: Is it safe to add the HashiCorp repository?
    A: Yes, the repository is officially provided and maintained by HashiCorp, and it uses a signed GPG key for added security.
  • Q: Can I install a specific version of Terraform?
    A: Yes, you can find available versions at the official HashiCorp releases page and manually download and install your desired version.
  • Q: How do I uninstall Terraform?
    A: You can remove Terraform by running sudo apt remove terraform. Also consider removing the HashiCorp repository if no longer needed.
  • Q: Does Terraform work with all cloud providers?
    A: Terraform supports a wide range of cloud providers through its plugin-based providers architecture, including AWS, Azure, GCP, DigitalOcean, and many more.
  • Q: Is Terraform suitable for production environments?
    A: Absolutely. Terraform is widely used in production environments due to its scalability, stability, and extensive ecosystem of modules and providers.
I'm Ava Taylor, a freelance web designer and blogger. Discussing web design trends, CSS tricks, and front-end development is my passion.
Back To Top