How to install terraform on linux | ubuntu | centos | Rhel

Terraform is one of the most popular automation devops tool used for various sort of automation. Terraform is mainly known for its provisioning capabilites. We can use terraform to deploy a virtual machine or any other resource on popular clouds like AWS, GCP and Azure. You can refer this tutorial to install Terraform on Linux, Ubuntu, CentOs, RHEL, etc.

Install terraform on Linux | Ubuntu | Centos | Rhel

Lets update the ubuntu packages

$sudo apt-get update

Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,328 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,386 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,592 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,771 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [1,983 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [383 kB]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages [1,080 kB]
Get:12 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,157 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [1,001 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [266 kB]
Fetched 13.2 MB in 14s (965 kB/s)
Reading package lists... Done

Once packages are updated, now we can install some utilities which will be required by Terraform

sudo apt-get install -y gnupg software-properties-common curl

Let install the GPG Key for HashiCorp

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

For installation of Terraform, we need to add the HashiCorp official repository to our ubuntu server.

$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 https://apt.releases.hashicorp.com bionic InRelease [9,497 B]
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
Get:5 https://apt.releases.hashicorp.com bionic/main amd64 Packages [39.3 kB]
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease
Fetched 48.8 kB in 0s (106 kB/s)
Reading package lists... Done

Now we are all set for installing the Terraform, please run below command install Terraform

sudo apt-get update && sudo apt-get install terraform
$ sudo apt-get update && sudo apt-get install terraform
Hit:1 https://apt.releases.hashicorp.com bionic InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  terraform
0 upgraded, 1 newly installed, 0 to remove and 268 not upgraded.
Need to get 18.7 MB of archives.
After this operation, 61.9 MB of additional disk space will be used.
Get:1 https://apt.releases.hashicorp.com bionic/main amd64 terraform amd64 1.1.0 [18.7 MB]
Fetched 18.7 MB in 5s (3,863 kB/s)
Selecting previously unselected package terraform.
(Reading database ... 66298 files and directories currently installed.)
Preparing to unpack .../terraform_1.1.0_amd64.deb ...
Unpacking terraform (1.1.0) ...
Setting up terraform (1.1.0) ...

We have installed Terraform successfully.

Verify Terraform installation

Lets run few commands to verify the terraform installation.

$ terraform --version
Terraform v1.1.0
on linux_amd64
$ terraform -help
Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

Terraform has got Tab auto-complete feature but its not enabled by default. This can be enabled for systems where you have bash. Lets enable Tab Auto-Complete feature. Lets check the bash presence in our current system.

touch ~/.bashrc

Run below command to enable the feature.

terraform -install-autocomplete

Lets try the auto-complete feature of Terraform. You need to restart shell to enable the auto-complete feature.

install terraform on linux

Conclusion

We have successfully installed Terraform and then we verified the Terraform installation by checking its version. We also enabled its Tab Auto-complete feature which gives linux shell like auto-complete by press of Tab button.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments