Home Linux How to Install and Configure Terraform in Linux Distributions

How to Install and Configure Terraform in Linux Distributions

Terraform is a free and open-source application that can automate and manage your infrastructure. Terraform helps to build services and platforms using declarative language; this means you don’t need to define every step of automation; it can learn by itself. You don’t have to worry about every step of your systems to automation; it can take care of that. If you a newbie on Terraform, it allows you to start from the starch. Terraform supports Ubuntu, Fedora, Arach, Red Hat, and other major Linux distributions. After installing Terraform on your Linux, it can be integrated with AWS, cloud, VM, and other systems.

Terraform in Linux


In Linux, the Terraform is executable with a command-line interface. Terraform was developed by HashiCorp, and written in the Go programming language, and built under the Mozilla Public License v2.0. It supports data sharing, API, access control. In this post, we will see how to install Terraform in Linux distributions.

1. Install Terraform in Debian, Ubuntu & Mint


Installing Terraform on a Ubuntu or Debian-based Linux system is easy and straightforward. It is available in the official Linux repository. First, run the flowing cURL command on your terminal shell to add the GPG key for Terraform to your system.

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -

Then, run the following command to download Terraform from the Hashicorp website.

$ sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

Finally, you can update your system repository and install Terraform on your Ubuntu system. The installation requires the root password.

$ sudo apt update
$ sudo apt install terraform

2. Install Terraform on Fedora and Red Hat Linux


If you are running a Fedora workstation or a Red Hat Linux on your machine, this step will guide you in installing Terraform on your system. The methods of installing Terraform on an earlier version of the DNF-based Fedora Linux machine includes both YUM and DNF command.

On the Red Hat Linux systems, you can first run the following YUM commands to add the YUM-utils and then run the next command to download it on your system.

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/$release/hashicorp.repo

If you’re using a DNF-based Fedora workstation, you can run the following commands on your terminal shell to add the DNF plugins and download the Terraform on your Linux system.

sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/$release/hashicorp.repo

Finally, run the following commands on your terminal shell to update your system repository and install Terraform on your machine.

$ sudo yum update
$ sudo yum install terraform

3. Download Terraform via wget and Install on Linux


If you find the Hashicorp repository URL doesn’t work on your local internet connection, you can change the repository location from your country to the Main server. If that doesn’t work either, there is an option that will allow you to install Terraform on your Linux machine.

First, you need to install wget tool on your system. Normally, wget comes pre-installed on both Debian and Red Hat systems. If you can’t find it on your machine, use the following commands to install it.

Install wget on Fedora/Red Hat Linux

sudo dnf install wget

Install wget on Debian/Ubuntu Linux

sudo apt install wget

When wget installation finishes, you can now run the following command on your terminal shell to download the compressed version of Terraform on your Linux filesystem. The wget command usually stores files inside the Home directory.

wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip

After downloading, browse your directory and run the unzip command to extract the file.

sudo unzip terraform_0.14.10_linux_amd64.zip

Now, run the following move command to move the Terraform files inside the /usr/local/bin/ directory. Make sure you’re the root user before running the following command.

sudo mv terraform /usr/local/bin/

After moving the Terraform files inside the /usr/local/bin directory, you may now run the which command given below to check whether Terraform works or not. In the return, you would get the directory where you kept the Terraform files.

$ which terraform

4. Install Terraform on Arch via Snap


If you’re using an Arch and Arch-based Linux system, you can install Terraform on your system through the Snap store. If you don’t have the Snap installed on your system, run the following git command-lines on your terminal shell to clone Snap from the Arch repository and enable the Snap daemon on your Arch Linux.

git clone https://aur.archlinux.org/snapd.git
cd snapd
makepkg -si

Now, run the following system control commands with access to enable the Snap socket and create a soft link of the Snap daemon on your system.

sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Finally, you can now run the following snap command to get the Terraform automation tool on your Arch system.

sudo snap install terraform --candidate

Arch Linux also offers you to download the compiled ZST package of Terraform that you can later install on your system through the default package installer. Please click here to download the ZST package of Terraform tool.

Get Started with Terraform on Linux


Till now, we have seen several methods of installing Terraform on a Linux system. After finishing the installation, finally, it would better if you run the following command on your terminal shell to check the version of Terraform. Any of the following commands will print the Terraform version.

$ terraform -v
$ terraform version

Final Words


After installing the Terraform automation tool on Linux, you can immediately run it on your machine to get started. If you’re using it on a cloud-based system or a virtual machine, ensure your system has an active internet connection, and you’ve deployed Terraform correctly. In the entire post, I’ve described the process of installing Terraform on most major Linux distributions.

Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version