TerraformPilot

Terraform

Install Terraform on RHEL and CentOS

Install Terraform on RHEL 9, RHEL 8, and CentOS Stream. Official HashiCorp repository, manual binary install, and version management with tfenv.

LLuca Berton1 min read

Quick Answer

#
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
terraform version
#

RHEL 9 / CentOS Stream 9

#
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo dnf -y install terraform

RHEL 8 / CentOS Stream 8

#
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform

Verify

#
terraform version
# Terraform v1.x.x

Method 2: Manual Binary Install

#
TERRAFORM_VERSION="1.8.5"
curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
sudo mv terraform /usr/local/bin/
rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
terraform version

For ARM systems (e.g., Graviton):

curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip"

Method 3: tfenv (Version Manager)

#
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
 
tfenv install latest
tfenv use latest
terraform version

Enable Tab Completion

#
terraform -install-autocomplete
source ~/.bashrc

Uninstall

#
# If installed via repo
sudo yum remove terraform
 
# If installed manually
sudo rm /usr/local/bin/terraform
#

Conclusion

#

Use the official HashiCorp repository for automatic updates via dnf/yum. Use tfenv when you need multiple versions for different projects. Use manual binary install for air-gapped or restricted environments.

#Terraform#RHEL#CentOS#Linux#Install

Share this article