Install Terraform on Ubuntu 24.04

|
Last Updated:
|
|
Install Terraform on Ubuntu 24.04

How can I install Terraform on Ubuntu 24.04 for automated deployments and infrastructure provisioning? This guide will provide step-by-step tutorial on installing Terraform on Ubuntu 24.04. Terraform is an Infrastructure as Code tool that enables you to provision various cloud or on-prem resources such your infrastructure servers, serverless cloud functions, Kubernetes clusters, networking tasks e.t.c in a versionable, reusable and shareable manner.

To learn the basics of Terraform, check the guide below;

Introduction to Terraform: Understanding Basic Architecture

Installing Terraform on Ubuntu 24.04

So, if you want to see Terraform in action on your local environment, how can you install it? Follow through this guide to learn how to install Terraform.

There are two ways in which you can install Terraform:

  • Install via APT Repository
  • Install using Binary file

Installing Terraform from APT Repository

Install HashiCorp APT Repository

Ubuntu default repositories do not provide Terraform package. As a result, you need to install the HashiCorp APT repository that let’s you install Terraform on your Ubuntu Linux system.

Run the commands below to install HashiCorp APT repository on Ubuntu 24.04.

Install the required packages to setup the repository.

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

Install the HashiCorp APT repository GPG key.

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp-archive-keyring.gpg

Install HashiCorp repository;

echo "deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

Install Terraform from HashiCorp Repository

Once the repository is installed, proceed to install Terraform.

sudo apt update
sudo apt install terraform

And Terraform should now be installed on your Ubuntu Linux system.

Installing Terraform using Binary file

If you do not want to install HashiCorp APT repositories, you can install Terraform using binary. Navigate to the Linux binary downloads page and grab a binary of your respective system architecture, e.g amd64;

wget https://releases.hashicorp.com/terraform/1.8.0/terraform_1.8.0_linux_amd64.zip

Once you have downloaded the binary, extract it to the system binaries directory. We use /usr/local/bin in this guide.

sudo unzip terraform_1.8.0_linux_amd64.zip -d /usr/local/bin/

Make the binary executable;

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

And that is it!

Using Terraform on CLI

As a verification that Terraform has been installed and functioning as expected, you can try to run a few Terraform commands;

terraform -version
Terraform v1.8.0
on linux_amd64
terraform -help
Usage: terraform [global options]  [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  metadata      Metadata related commands
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  test          Execute integration tests for Terraform modules
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.

Getting Started with Terraform

You can now get started with Terraform to provision your infrastructure.

Read more on Terraform Tutorials page.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment