Terraform is an open-source Infrastructure as Code tool that helps you manage and create your infrastructure using one interface for multiple providers. The software lets you automate infrastructure provisioning using machine-readable configuration files.
This guide will show you how to install Terraform on CentOS using two different methods.
- A user account with sudo privileges.
- wget and unzip installed.
- Access to the terminal/command-line tool.
Install Terraform on CentOS
There are two methods to install Terraform on CentOS. The primary method is using the Terraform zip archive that contains the executable you can unpack anywhere on your system.
The other method is using HashiCorp repository for CentOS systems.
Install Terraform on CentOS Using Zip Archive
To install Terraform on a CentOS system using the downloaded zip file, follow the steps below:
1. Browse to the Download Terraform page.
2. Select the Linux tab under the Operating System heading. The latest version is preselected.
3. Scroll down and right click the Download button for your system’s architecture. In our case, it is AMD64. Select Copy Link.
4. Use the wget tool to download the file:
wget <a href="https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_linux_amd64.zip">https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_linux_amd64.zip</a>
5. Chose a user directory in &PATH where you will extract the Terraform binary:
This guide will use /usr/local/bin.
6. Unzip the file to the selected location. Use the full zip archive name including the extension:
sudo unzip terraform_1.3.5_linux_amd64.zip -d /usr/local/bin
Note: The file name is different for different versions and different architectures. Copy the file name after you download it.
The output shows the terraform directory where the extracted file is located. Optionally, you can use the list command to check if the Terraform directory is located in the selected location. In our case:
ls -l /usr/local/bin
7. Run the command to check the Terraform version and verify the installation is successful:
The output shows the Terraform version you downloaded.
Install Terraform on CentOS Using Package Repository
The HashiCorp repository contains other non-Terraform packages that will be available for installing after you add the repository.
Follow the steps to install Terraform from the official HashiCorp repository on a CentOS system.
1. Install the yum-utils tools:
sudo yum install -y yum-utils
2. Add the HashiCorp repository:
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
3. Finally, install Terraform using the yum package manager:
sudo yum -y install terraform
The output show that Terraform is installed. You can double-check by running the
terraform -version command to see the installed Terraform version.
In this guide, we covered how to install Terraform on CentOS using the Terraform binary and the official HashiCorp repository.
Check out our article comparing Terraform vs Puppet for further reading or learn how to install Terraform on Windows, macOS, or other Linux distributions.