Greenwebpage Community Blog Tutorials How to Install Terraform on Ubuntu 24.04
Tutorials

How to Install Terraform on Ubuntu 24.04

Terraform is powerful software that allows you to manage and set up computer systems and networks. It can efficiently manage your infrastructure and workflow, including writing, planning, and applying operations.

In short, Terraform enables you to set up, modify, and track cloud and local resources efficiently.

This article presents you with the illustrated guide to setup Terraform on the Ubuntu 24.04 system.

How to Install Terraform on Ubuntu 24.04?

The post will cover the following sequential steps to install Terraform on Ubuntu 24.04:

Method 1: How to Install Terraform on Ubuntu 24.04 through APT Repository?

Method 2: How to Install Terraform on Ubuntu 24.04 from Binary?

How to Uninstall Terraform from Ubuntu 24.04?

Conclusion

Method 1: How to Install Terraform on Ubuntu 24.04 through APT Repository?

Following this guide will install Terraform on your Ubuntu 24.04 machine.

Step 1: Updated and Upgraded System Packages

Keeping updated your Ubuntu machine can enhance your system performance. Therefore, you must run this command before installing the new package like Terraform :

sudo apt update

Sometimes, the command will recommend you to upgrade the outdated packages.

You can upgrade all the required packages with this simple command:

sudo apt upgrade -y

The updating process will be displayed on your screen. You can review these packages during the installation.

Step 2: Install Required Packages

To avoid dependency issues, ensure that you have already installed the following packages. If not, run this command:

sudo apt install gnupg software-properties-common -y

If these necessary packages are already installed on your system, the command will confirm their installation.

Step 3: Download the HashiCorp GPG key for Terraform

Next, download the HashiCorp GPG key for Terraform to your system repository using the command attached below:

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

As shown above, the HashiCorp GPG key is now available in your repository.

Step 4: Add the HashiCorp APT Repository

To allow your Ubuntu system to install packages like Terraform from HashiCorp, use the following command to add the HashiCorp APT repository to your system’s list:

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

The above script added the HashiCorp repository for Terraform to your Ubuntu 24.04 system.

Step 5: Update Ubuntu Package List

Run the Update command to incorporate the HashiCorp repository to your system:

sudo apt update

After updating your system, you will see the HashiCorp repository in your system’s repository list.

Step 6: Install Terraform via APT

Once you have added the new repository to your package list, run the install command to set up Terraform on Ubuntu 24.04:

sudo apt install terraform -y

You will see in the output that an updated version of Terraform has been installed and configured on your Ubuntu 24.04 system.

Method 2: How to Install Terraform on Ubuntu 24.04 from Binary?

You can manually install the Terraform from the binary file using these instructions.

Step 1: Access Terraform Official Web Page

Enter the attached URL to the Web browser to access the installation page of Terraform. Then:

  • Locate the Binary download category.
  • Right-click on AMD64.
  • Select Copy the Link.

https://developer.hashicorp.com/terraform/install

Note: You can download the Terraform Binary by directly clicking on the “Download” button.

Step 2: Download the Terraform Binary

Use the “wget” command followed by the Terraform Binary link to download the file:

wget https://releases.hashicorp.com/terraform/1.9.3/terraform_1.9.3_linux_amd64.zip

The Terraform binary is now downloaded as a ZIP file (i.e. terraform_1.9.3_linux_amd64.zip)on your local machine.

Step 3: Extract Terraform Downloaded File

To utilize the Terraform package, first, extract or unzip the downloaded file with this command:

unzip terraform_1.9.3_linux_amd64.zip

Verify the unzipped file of Terraform using the below command:

ls

If you find the “terraform” folder on your screen, it means the file is successfully unzipped to your machine.

Step 4: Copy the Terraform to the System’s PATH

Use the “mv” command to move the unzipped binary to your system’s PATH, such as “/usr/local/bin”:

sudo mv terraform /usr/local/bin/ -v

This step is essential for moving the Terraform binary to the system’s PATH, making it easy to run Terraform commands from anywhere in your Terminal.

Step 5: Verify Terraform Installation

After configuring the Terraform package, confirm its installation:

terraform -v

You can see that the updated version of Terraform v1.9.3 has been installed and configured on the Ubuntu 24.04 system.

How to Uninstall Terraform from Ubuntu 24.04?

You can follow these methods to remove or uninstall the Terraform package from your Ubuntu 24.04.

Method 1: How to Uninstall Terraform from Ubuntu 24.04 with APT?

The following command is useful if you have installed the Terraform using the APT manager. To uninstall the Terraform completely, use this command:

sudo apt purge --autoremove terraform -y

The Terraform package files are no longer available on Ubuntu 24.04.

Method 2: How to Remove Terraform from Ubuntu 24.04 Manually?

If you have manually installed the Terraform from the Binary file, then use this command to remove it:

sudo rm /usr/local/bin/terraform -v

The “-v” flag is added to show you that the Terraform has been removed from your Ubuntu 24.04 system.

Conclusion

Terraform can be installed on Ubuntu 24.04 using two methods. You can install it from the APT repository by adding the HashiCorp GPG key and then operating “sudo apt install terraform”.

Alternatively, if you prefer to install Terraform from the binary file, manually; download the Terraform*.zip file, unzip it, and move the binary to the system’s PATH using “sudo mv terraform /usr/local/bin/”.

Exit mobile version