How to Install Terraform on CentOS 8

To install Terraform using the binary package, you can follow these general steps. Terraform is available for various operating systems, so I’ll provide instructions for Linux CentOS servers.

To install Terraform using Binary Package on CentOS 8, you can use the following steps:

Update the Package Repository:

Start by updating the package repository on your CentOS 8 system:


sudo dnf update

Download Terraform Binary:

You can download the Terraform binary from the official website. Visit the Terraform downloads page to find the URL for the latest version of Terraform: Terraform Downloads.

You can use curl to download the binary. Replace <VERSION> in the URL below with the version you want to install (e.g., 0.14.11):


curl -LO https://releases.hashicorp.com/terraform/<VERSION>/terraform_<VERSION>_linux_amd64.zip

Install Unzip (if not already installed):

If you don’t already have the unzip utility installed on your system, you can install it using dnf:


sudo dnf install unzip

Unzip the Terraform Binary:

Unzip the downloaded Terraform binary:


unzip terraform_<VERSION>_linux_amd64.zip

This will extract the terraform binary.

Move the Binary to /usr/local/bin:

It’s a good practice to move the Terraform binary to a directory that is included in your system’s PATH. /usr/local/bin is a common location for user-installed binaries:


sudo mv terraform /usr/local/bin/

Verify the Installation:

To verify that Terraform was installed correctly, you can check the version:


terraform --version

You should see the version number of Terraform printed in the terminal.

Terraform should now be installed and ready to use on your CentOS 8 system. You can start using Terraform to manage your infrastructure as code.

How to Install Terraform using Package Manager on CentOS 8

Certainly, another way to install Terraform is by using a package manager that is available for your operating system. Below are instructions for installing Terraform using popular package manager: Homebrew for macOS and Linux package managers (e.g., apt for Debian/Ubuntu and yum for CentOS/Red Hat). Here we will discuss dnf/yum package manager for CentOS 8 operating system.

To install Terraform on CentOS 8, you can use the official HashiCorp repository. Here are the steps to install Terraform:

Add the HashiCorp YUM Repository:

First, create a file for the HashiCorp repository in the /etc/yum.repos.d/ directory. You can use a text editor like nano or vi for this. Run the following command:


sudo nano /etc/yum.repos.d/hashicorp.repo

Then, add the following content to the file and save it:


[hashicorp]
name=HashiCorp Stable - $basearch
baseurl=https://rpm.releases.hashicorp.com/RHEL/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://rpm.releases.hashicorp.com/gpg

Install Terraform:

Now that you’ve added the HashiCorp repository, you can install Terraform using dnf:


sudo dnf install terraform
HashiCorp Stable - x86_64                                                                                                                                    1.7 MB/s | 1.2 MB     00:00
Dependencies resolved.
=====================================================================================================
 Package                                       Architecture                               Version                                        Repository                                     Size
=====================================================================================================
Installing:
 terraform                                     x86_64                                     1.5.7-1                                        hashicorp                                      21 M

Importing GPG key 0xA621E701:
 Userid     : "HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>"
 Fingerprint: 798A EC65 4E5C 1542 8C8E 42EE AA16 FCBC A621 E701
 From       : https://rpm.releases.hashicorp.com/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                     1/1
  Installing       : terraform-1.5.7-1.x86_64                                                                                                                                            1/1
  Verifying        : terraform-1.5.7-1.x86_64                                                                                                                                            1/1

Installed:
  terraform-1.5.7-1.x86_64

Complete!

Confirm the installation by typing “y” when prompted.

Verify the Installation:

After the installation is complete, you can verify that Terraform is installed correctly by checking its version:


terraform --version
Terraform v1.5.7
on linux_amd64

This command should display the installed Terraform version.

That’s it! You’ve successfully installed Terraform on CentOS 8 using the HashiCorp repository. You can now start using Terraform to manage your infrastructure as code.

References:

https://www.terraform.io/
https://developer.hashicorp.com/terraform/intro
https://registry.terraform.io/
https://registry.terraform.io/providers/hashicorp/terraform/latest
https://developer.hashicorp.com/terraform/language/resources
https://www.pluralsight.com/resources/blog/cloud/the-ultimate-terraform-cheatsheet

Asif Khan

Asif Khan

DevOps, Linux, and Cloud engineer with 10+ years building infrastructure that stays up, and automation so I do not have to fix it at 2am. My focus is automation, security, and systems built to survive failure, using Infrastructure as Code, CI/CD, containers, monitoring, and cloud platforms instead of manual fixes. This blog is where I write down what worked, and just as often what didn't the first time around. Real tutorials you can run yourself, troubleshooting notes pulled from actual outages, and the kind of detail you only get once you've hit the problem firsthand. If you're trying to get Linux, DevOps, and cloud infrastructure to behave, that's what you'll find here: reproducible solutions you can understand, test, and apply in your own environment.