Terraform is an open-source infrastructure as code (IaC) software tool that allows you to build, change, and version infrastructure safely and efficiently. It can manage popular service providers and custom in-house solutions. This article provides a step-by-step guide on how to install Terraform on Ubuntu 22.04 and 20.04 using PPA (Personal Package Archive).
Before beginning the installation process, ensure that you have:
- A Ubuntu 22.04 or 20.04 system.
- A user account with sudo privileges.
- An internet connection for downloading necessary files.
Step 1: Update the System
Before installing any new software, it is recommended to update your system’s package list. You can update your system with the following command:
sudo apt update
sudo apt upgrade
You’ll need curl and some software-properties-common packages to add the repository key and repository. Run the following commands to install them:
sudo apt install curl software-properties-common
Step 2: Add the HashiCorp Repository
Terraform is developed by HashiCorp, and you need to add the HashiCorp GPG (GNU Privacy Guard) key with the following command:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
Once the key is added, 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
Step 3: Install Terraform
After adding the repository, you can install Terraform with the following command:
sudo apt update && sudo apt install terraform
Step 4: Verify the Installation
To ensure Terraform has been installed successfully, check the version with the following command:
You should see the version of your installed Terraform.
Output:Terraform v1.5.2 on linux_amd64
Step 5: Get Started with Terraform
Now that Terraform is installed, you can start using it to manage and automate your infrastructure. Begin by creating a new directory for your Terraform project:
Create a new file named main.tf. This will be your project’s main configuration file:
From here, you can begin writing your Terraform configurations according to the needs of your project.
That’s it! You’ve successfully installed Terraform on your Ubuntu 22.04 or 20.04 system using PPA. Now, you can begin creating infrastructure as code, which will improve the manageability and predictability of your environments. Happy Terraforming!
Remember, Terraform is a powerful tool that allows you to manage infrastructure using configuration files, which describe the resources you want to have. It’s essential to understand how Terraform works before you start working with it in a production environment. Always test your configurations before deploying them and make sure to version control your Terraform files.