How to Install Terraform (Infrastructure as Code) in Linux

In this article, we will discuss what Terraform is and how to install Terraform on various Linux distributions using HashiCorp repositories.

What is Terraform?

Terraform is a popular cloud orchestration tool in the world of automation, which is used to deploy your infrastructure through the IAC (Infrastructure as code) approach.

Terraform is built by Hashicorp and released under Mozilla Public License. It supports public, private as well and hybrid cloud, as of now Terraform supports 145 providers, which include popular providers like AWS, Azure Cloud, GCP, Oracle Cloud, and many others.

Terraform architecture is very simple. All you need is to download the terraform binary to your local/server machine which is going to act as your base machine.

We have to mention the provider to work within our syntax file. Terraform will download the plugin for that particular provider automatically and will authenticate with the provider API to execute the plan.

What is Infrastructure as Code?

The process of provisioning and managing resources like Virtual Machines, Storage, Networks, Database, etc.. through machine-readable definition files, rather than interactive tools or hardware configurations.

Features
  • Open-source.
  • Declarative syntax.
  • Pluggable Modules.
  • Immutable infrastructure.
  • Simple client-only architecture.

Let’s get started…

Installing Terraform in Linux Distributions

The Terraform primary distribution packages come in .zip format, that includes single executable files that you can uncompress at any location on your Linux system.

However, for simpler integration with configuration management tools, terraform also offers package repositories for Debian-based and RHEL-based systems, which enables you to install Terraform using your default package management tools called APT, Yum, or DNF.

Install Terraform in Debian, Ubuntu & Mint

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
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
sudo apt update 
sudo apt install terraform

Install Terraform in RHEL and CentOS

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

Install Terraform in Fedora

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

Now the installation can be verified by running a simple terraform version command.

$ terraform version
Check Terraform Version
Check Terraform Version

That’s it for this article. The installation is very simple and easy to set up and some text editors like Sublime and VSCode come with language support for Terraform too.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Karthick
A passionate software engineer who loves to explore new technologies. He is a public speaker and loves writing about technology, especially about Linux and open source.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
  1. apt-key has been deprecated on Linux Mint 21 – another means needs to be used to import the key.

    apt update has been updated to require a Release file. This command fails on Linux Mint 21 as used above.

    Reply
  2. Thanks for the article!

    Just note when you’re installing Terraform via the CLI on Debian family distros, you have to include below command to update package.

    $ sudo apt update
    

    If it’s not executed you’ll see something as below:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package terraform
    

    I guess the same is happening for the Red Had family distros.

    Thanks,
    Pablo

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.