How to Install Terraform on Linux [2 Steps]

In this article we are going to cover How to Install Terraform on Linux, How to Install Terraform on Ubuntu/Debian using APT, How to Install Terraform on CentOS/RHEL using YUM config manager, How to Install Terraform on Fedora using dnf config manager and Install Terraform on Amazon Linux using YUM config manager.

Prerequisites

  • Preinstalled Linux with minimal Installation
  • SSH access with sudo privileges

How to Install Terraform on Linux by downloading Zip archive

First download the latest terraform version setup from Terraform Official Site using wget.

wget https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip

Output:

 https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.153.183, 2a04:4e42:24::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.153.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33783879 (32M) [application/zip]
Saving to: ‘terraform_0.14.7_linux_amd64.zip’

100%[=============================================================================================>] 33,783,879   113MB/s   in 0.3s

2021-03-13 03:57:29 (113 MB/s) - ‘terraform_0.14.7_linux_amd64.zip’ saved [33783879/33783879]

Extract the downloaded setup using unzip

sudo unzip terraform_0.14.7_linux_amd64.zip

Output:

Archive:  terraform_0.14.7_linux_amd64.zip
  inflating: terraform

Move the extracted setup to /usr/local/bin directory

sudo mv terraform /usr/local/bin/

Lets verify Terraform version on Amazon Linux using below command

terraform -v

Output:

Terraform v0.14.7

Lets check Terraform commands

terraform -help

Output:

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

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.

Uninstall terraform from Amazon Linux, remove terrform from /usr/bin or /usr/local/bin directory

sudo rm -rf /usr/bin/terraform

OR

sudo rm -rf /usr/local/bin/terraform

How to Install Terraform on Ubuntu/Debian using APT

Add the Hashicorp signing key in Ubuntu/Debian

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

Add the Hashicorp official apt reposity

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

Install the latest version of terraform on ubuntu/terraform

sudo apt install terraform

To check current and all versions of terraform

apt policy terraform

select the specific terraform version and install it

sudo apt install terraform=0.14.0

To uninstall terraform from ubuntu using apt

sudo apt remove terraform

How to Install Terraform on CentOS/RHEL using YUM config manager

Install yum-config-manager in CentOS/RHEL Linux repositories.

sudo yum install -y yum-utils

Add the official HashiCorp Linux repository in yum-config-manager.

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

Install Terraform on CentOS/RHEL

sudo yum -y install terraform

To check Terraform version on Amazon Linux using command

terraform -v

Lets check Terraform commands

terraform -help

To Uninstall Terraform from Amazon Linux using YUM

sudo yum -y remove terraform

How to Install Terraform on Fedora using dnf config manager

Install dnf plugins using below command

sudo dnf install -y dnf-plugins-core

Add the official HashiCorp Linux repository in dnf-config-manager.

sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo

Install terraform on Fedora using dnf

sudo dnf -y install terraform

Check the if terraform is working

terraform -help

Install Terraform on Amazon Linux using YUM config manager

Install yum-config-manager to Amazon Linux repositories.

sudo yum install -y yum-utils

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                      | 3.7 kB  00:00:00
Package yum-utils-1.1.31-46.amzn2.0.1.noarch already installed and latest version

Add the official HashiCorp Linux repository in yum-config-manager.

sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
adding repo from: https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
grabbing file https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo to /etc/yum.repos.d/hashicorp.repo
repo saved to /etc/yum.repos.d/hashicorp.repo

Install Terraform on Amazon Linux

sudo yum -y install terraform

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                      | 3.7 kB  00:00:00
hashicorp                                                                                                       | 1.4 kB  00:00:00
hashicorp/2/x86_64/primary                                                                                      |  39 kB  00:00:00
hashicorp                                                                                                                      257/257
Resolving Dependencies
--> Running transaction check
---> Package terraform.x86_64 0:0.14.8-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
 Package                          Arch                          Version                         Repository                        Size
=======================================================================================================================================
Installing:
 terraform                        x86_64                        0.14.8-1                        hashicorp                         26 M

Transaction Summary
=======================================================================================================================================
Install  1 Package

Total download size: 26 M
Installed size: 79 M
Downloading packages:
warning: /var/cache/yum/x86_64/2/hashicorp/packages/terraform-0.14.8-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a3219f7b: NOKEY
Public key for terraform-0.14.8-1.x86_64.rpm is not installed
terraform-0.14.8-1.x86_64.rpm                                                                                   |  26 MB  00:00:03
Retrieving key from https://rpm.releases.hashicorp.com/gpg
Importing GPG key 0xA3219F7B:
 Userid     : "HashiCorp Security (HashiCorp Package Signing) <[email protected]>"
 Fingerprint: e8a0 32e0 94d8 eb4e a189 d270 da41 8c88 a321 9f7b
 From       : https://rpm.releases.hashicorp.com/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : terraform-0.14.8-1.x86_64                                                                                           1/1
  Verifying  : terraform-0.14.8-1.x86_64                                                                                           1/1

Installed:
  terraform.x86_64 0:0.14.8-1

Complete!

To check Terraform version on Amazon Linux using command

terraform -v

Output:

Terraform v0.14.8

Lets check Terraform commands

terraform -help

Output:

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

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.

To Uninstall Terraform from Amazon Linux using YUM

sudo yum -y remove terraform

Output:

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package terraform.x86_64 0:0.14.8-1 will be erased
--> Finished Dependency Resolution
amzn2-core/2/x86_64                                                                                             | 3.7 kB  00:00:00

Dependencies Resolved

=======================================================================================================================================
 Package                         Arch                         Version                           Repository                        Size
=======================================================================================================================================
Removing:
 terraform                       x86_64                       0.14.8-1                          @hashicorp                        79 M

Transaction Summary
=======================================================================================================================================
Remove  1 Package

Installed size: 79 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : terraform-0.14.8-1.x86_64                                                                                           1/1
  Verifying  : terraform-0.14.8-1.x86_64                                                                                           1/1

Removed:
  terraform.x86_64 0:0.14.8-1

Complete!

Conclusion:

We have covered How to Install Terraform on Linux, How to Install Terraform on Ubuntu/Debian using APT, How to Install Terraform on CentOS/RHEL using YUM config manager, How to Install Terraform on Fedora using dnf config manager and Install Terraform on Amazon Linux using YUMconfig manager

Related Articles:

Creating EC2 Instance using Terraform

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link