Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Install Terraform on CentOS

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Terraform is HashiCorp's infrastructure-as-code tool that lets you define and provision cloud and on-premises resources using declarative configuration files. This guide walks you through installing Terraform on CentOS (7, 8, or 9) using the official HashiCorp repository, which is the recommended method because it provides automatic updates and verified binaries. You'll need a CentOS system with sudo access and an internet connection. No prior Terraform experience is required.

What You'll Need

  • A CentOS machine (7, 8, or 9) with internet access
  • A user account with sudo privileges
  • Basic familiarity with the command line

Step-by-Step

  1. Update your system (recommended). Open a terminal and run:
    sudo yum update -y
    On CentOS 8+ you can use dnf instead; both work in this guide.
  2. Install required dependencies. Terraform needs wget and unzip to download and extract the binary if you choose the manual method. For the repository method, you'll need yum-utils or dnf-plugins-core to manage the repo. Install them with:
    sudo yum install -y yum-utils wget unzip
  3. Add the HashiCorp repository. The official repo is the cleanest way to install Terraform. Run:
    sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
    If yum-config-manager is not found, install it with sudo yum install -y yum-utils first.
  4. Verify the repository is enabled. Check with:
    sudo yum repolist
    You should see a hashicorp entry listed.
  5. Install Terraform. Now install the package:
    sudo yum install -y terraform
    This installs the latest stable version.
  6. Verify the installation. Check the version to confirm everything works:
    terraform version
    You should see output like Terraform v1.x.x.
  7. Enable tab completion (optional but handy). Add the completion script to your shell profile:
    terraform -install-autocomplete
    Then restart your shell or run source ~/.bashrc.

If you prefer to install manually (e.g., to pin a specific version), download the binary from terraform.io/downloads, unzip it, and move it to /usr/local/bin. For example:

wget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip
unzip terraform_1.5.7_linux_amd64.zip
sudo mv terraform /usr/local/bin/

Common Mistakes

  • Using the wrong repo URL. The official repo is for RHEL, but it works on CentOS. Do not use the Debian/Ubuntu repo on CentOS.
  • Forgetting to enable the repo. Some versions of CentOS may not automatically enable third-party repos. Run sudo yum-config-manager --enable hashicorp if needed.
  • Installing from EPEL. EPEL may offer an older Terraform version. Stick with the HashiCorp repo for the latest.
  • Not checking PATH. If you manually install to a custom directory, ensure it's in your PATH or you'll get "command not found".

Tips

  • Use sudo yum update terraform to upgrade Terraform later; the repo handles updates.
  • Set up a separate directory for each Terraform project to keep state files and configurations organized.
  • Use terraform init in a new project to download provider plugins.
  • Consider using a version manager like tfenv if you work on multiple projects with different Terraform versions.

Troubleshooting

  • "yum-config-manager: command not found": Install yum-utils: sudo yum install -y yum-utils.
  • "No package terraform available": The repo might not be enabled. Run sudo yum-config-manager --enable hashicorp and try again.
  • GPG key errors: The repo uses a GPG key. If you get a key import prompt, accept it. If it fails, re-import the key manually:
    sudo rpm --import https://rpm.releases.hashicorp.com/gpg
  • "terraform: command not found" after manual install: Check that the binary is in your PATH. Run echo $PATH and move the binary to a directory listed, like /usr/local/bin.
  • Permission denied when running terraform: Ensure the binary has execute permissions: sudo chmod +x /usr/local/bin/terraform.

Frequently Asked Questions

Can I install Terraform on CentOS 6?

CentOS 6 is end-of-life and not officially supported by HashiCorp. It's strongly recommended to upgrade to a supported version.

Is the HashiCorp repo safe to use?

Yes, it's the official repository maintained by HashiCorp. Packages are signed with their GPG key.

How do I uninstall Terraform?

Run sudo yum remove terraform. This removes the binary but leaves your configuration files and state files untouched.

Can I install multiple versions of Terraform?

Yes, you can use a tool like tfenv or manually download binaries to different directories and switch via symlinks. The repo method installs only one version.

Do I need to install anything else to use Terraform with AWS/Azure/GCP?

No, Terraform downloads the necessary provider plugins when you run terraform init. You just need credentials for your cloud provider.

Why is my installed version older than the latest?

The repo may lag slightly. You can always download the latest binary manually from the official site.