Install terraform on Ubuntu 20.04, CentOS 8, MacOS, Windows 10, Fedora 33, Red hat 8 and Solaris 11
In this guide, we will focus on Installation of Terraform on a various operating system such as Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8, and Solaris.
- Install Terraform on Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8 or Solaris
- Install Terraform on Windows 10
- Install Terraform on MacOS
Later we are also going to see How to Upgrade Terraform using tfenv?
- Upgrade Terraform using tfenv
- Upgrade Terraform to Specific version using tfenv
- Uninstall the Terraform
1. Installing Terraform on Ubuntu 20.04, CentOS 8, Fedora 33, Red Hat 8, or Solaris
The instructions and command for installing Terraform on Ubuntu 20.04
OR CentOS 8
OR Fedora 33|32|31
is almost same. You only need to pay attention to which version of the host OS you are choosing. Is it 32 bit or 64 Bit?
1.1 Install the Terraform using official Package distribution
Ubuntu
- Update apt-get package manager
1sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
- Install official hashicorp repository
1curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
1sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
- Install terraform
1sudo apt-get update && sudo apt-get install terraform
Centos
- Install yum-config-manager
1sudo yum install -y yum-utils
- Add official HashiCorp Linux repository
1sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
- Install
1sudo yum -y install terraform
Fedora
- Install yum-config-manager
1sudo dnf install -y dnf-plugins-core
- Add official HashiCorp Linux repository
1sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
- Install terraform
1sudo dnf -y install terraform
1.2 The manual way to install Terraform
To install terraform manually you first need to download the terraform zip file from the hasicorp official website and to download zip file on the linux machine you need wget utility.
In case if you do not have wget
then use the following command to install it -
- Ubuntu 20.04 | 18.10 | 18.04 :
1sudo apt-get install wget unzip
- CentOS 8 | 7 :
1sudo yum install wget unzip
- Fedora 33 | 32 | 31 :
1bash sudo dnf install wget
Download the terraform.zip file
1. Goto Terrafrom.io
2. Click on Download CLI and for Ubuntu
3. On the download page you will find an option Linux, so based on your operating system architecture choose a suitable option (32-bit | 64-bit | Arm | Arm64). I choose the 64 bit
4. Right-click on 64-Bit option then click on Copy Link Location (We need to copy the download link)
5. Open Terminal and use the wget
command followed by the link which you copied in the previous step.
1wget https://releases.hashicorp.com/terraform/0.14.7/terraform_0.14.7_linux_amd64.zip
- After successful download you will see a
ZIP
file inside your directory
Unzip and move the file to '/usr/local/bin'
1. Unzip the terraform ZIP file
1unzip terraform_0.14.7_linux_amd64.zip
2. After the UNZIP you should see a file named terraform
3. Move the file terraform
to /usr/local/bin
1sudo mv terraform /usr/local/bin/
Verify the Terraform installation on Ubuntu
You can confirm the installation by running the following command
1terrafrom -v
It should return you with the version which you have installed. In my case, the version was - Terraform v0.14.7
1Terraform v0.14.7
2. Installing Terraform on Windows 10
Download the terraform.zip file
1. Head over to Terrafrom.io and click on [Download CLI](https://www.terraform. io/downloads.html)
2. Scroll down the page and look for the Windows option. After that you need to select the version 32 Bit | 64 Bit. (In my case I had 64 Bit Windows 10, so I choose 64 Bit option for download)
3. Once you click on either 32 Bit or 64 Bit, it will download a ZIP file for you.
Move and Extract the Terraform ZIP file
1. let's move the ZIP file to some good location. In my case, I moved the file to C:\Terraform
(You can move the
ZIP file to any location of your choice but always remember the path onto which you are moving the file)
2. Extract the Terraform ZIP file (After the extraction it should have one file terraform.zip
)
Add the Terraform directory PATH to Windows 10 environment variable
1. Copy the path of the folder where you placed terraform.exe
(In my case the path was C:\Terraform
)
2. Goto Start Menu
and type in the Environment Variables
in the search box and then click on Open
3. Once you open the environment variables window you need to click on Environment Variables
(You can find it
at the bottom of the window)
4. Goto -> System Variables
then look for the system variable named Path
5. Click on Edit
and it should open another window. Click on new
and past the path of your terraform directory
Verify the Terraform installation on Windows 10
You can verify the installation by opening the command prompt
and then typing the following command -
1terraform -v
If you have successfully installed the terraform then it should return you with the version number.
3. Installing Terraform on MacOS
Install the Terraform on MacOS using brew
This is one of my favorite ways to install any package on my macOS, but here are the steps for installing Terraform using HomeBrew
1. Use the following Homebrew
command it will install the Terraform for you.
1brew install terraform
1==> Downloading https://homebrew.bintray.com/bottles/terraform-0.14.3.catalina.bot
2==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/1172ae8f9a7ac2bed83ca13
3######################################################################## 100.0%
4==> Pouring terraform-0.14.3.catalina.bottle.tar.gz
5🍺 /usr/local/Cellar/terraform/0.14.3: 6 files, 63.9MB
Install Terraform manually on macOS
1. You can download the Terrafrom.io from [Download CLI](https://www.terraform. io/downloads.html)
2. Extract the downloaded ZIP file
3. Move the ZIP file using the following command
1sudo mv $HOME/Downloads/terraform /usr/local/bin/
Verify the Terraform installation on macOS
You can verify the Installation of Terraform on macOS by running the following command
1terraform -v
It should return you with the version which you have installed onto your macOS
1Terraform v0.14.3
4. Upgrade Terraform using tfenv
4.1 Install tfenv
on Ubuntu 20.04 | CentOS 8 | Fedora 33 | Red hat 8 | Solaris 11
The installation of tfenv
is pretty straight forward but you should at least know how to do git clone
or you
should be familiar with git
.
1. Clone the tfenv
repo
1git clone https://github.com/tfutils/tfenv.git ~/.tfenv
2. Add ~/.tfenv/bin to your $PATH
1echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
3. Create symlink for ~/.tfenv/bin/*
1mkdir -p ~/.local/bin/
1. ~/.profile
1ln -s ~/.tfenv/bin/* ~/.local/bin
1which tfenv
4.2 Verify the tfenv
installation
You can use the following command to verify the installation of tfenv
1tfenv
It should return you with version
1tfenv 2.2.0
2Usage: tfenv <command> [<options>]
3
4Commands:
5 install Install a specific version of Terraform
6 use Switch a version to use
7 uninstall Uninstall a specific version of Terraform
8 list List all installed versions
9 list-remote List all installable versions
10 version-name Print current version
11 init Update environment to use tfenv correctly.
4.3 List available version using $ tfenv list-remote
Before upgrading Terraform version, you should check which versions of Terraform are available.
Run the following command to check the available version
1tfenv list-remote
You will see the following output based on the latest available version -
10.15.0-beta1
20.15.0-alpha20210210
30.15.0-alpha20210127
40.15.0-alpha20210107
50.14.7
60.14.6
70.14.5
80.14.4
90.14.3
100.14.2
110.14.1
120.14.0
4.4 Install the latest version of Terraform
There is the default latest command provided by tfenv
which will install the latest version of Terraform onto your system
1tfenv install latest
5. Upgrade to a specific version of Terraform
If you really want to upgrade to a specific version of Terraform then always keep the correct version of Terraform handy with you. (At the time of writing this article the latest stable version of Terraform is 0.14.7
)
1tfenv install 0.14.7
There is one more feature provided by the tfenv
. If you want to upgrade to the latest version of some specific
release for example you want the latest version from 0.14 release then you can do it by running -
1tfenv install latest:^0.14
5.1 Change terraform version (If you have already installed multiple versions of Terraform)
Let's say you have installed multiple version(0.14.7, 0.14.6, 0.14.5) of terraform and now you want to switch between the versions then use the following command to achieve that
1tfenv use 0.14.6
The above command will switch to terraform to version 0.14.6
But if you use only terraform use
then it will switch the latest version of Terraform.
1 tfenv use
The above command will switch to version 0.14.7
because at the time of writing this article 0.14.7
is latest
the version provided by terraform
6. Uninstall the Terraform
The uninstallation command of the Terraform is very simple -
1tfenv uninstall 0.14.7
1Uninstall Terraform v0.14.7
2Terraform v0.14.7 is successfully uninstalled
Read More - Terragrunt -
Posts in this Series
- Use Terraform to manage AWS IAM Policies, Roles and Users
- How to split Your Terraform main.tf File into Multiple Files
- How to use Terraform variable within variable
- Mastering the Terraform Lookup Function for Dynamic Keys
- Copy files to EC2 and S3 bucket using Terraform
- Troubleshooting Error creating EC2 Subnet InvalidSubnet Range The CIDR is Invalid
- Troubleshooting InvalidParameter Security group and subnet belong to different networks
- Managing strings in Terraform: A comprehensive guide
- How to use terraform depends_on meta argument?
- What is user_data in Terraform?
- Why you should not store terraform state file(.tfstate) inside Git Repository?
- How to import existing resource using terraform import comand?
- Terraform - A detailed guide on setting up ALB(Application Load Balancer) and SSL?
- Testing Infrastructure as Code with Terraform?
- How to remove a resource from Terraform state?
- What is Terraform null Resource?
- In terraform how to skip creation of resource if the resource already exist?
- How to setup Virtual machine on Google Cloud Platform
- How to use Terraform locals?
- Terraform Guide - Docker Containers & AWS ECR(elastic container registry)?
- How to generate SSH key in Terraform using tls_private_key?
- How to fix-Terraform Error acquiring the state lock ConditionalCheckFiledException?
- Terraform Template - A complete guide?
- How to use Terragrunt?
- Terraform and AWS Multi account Setup?
- Terraform and AWS credentials handling?
- How to fix-error configuring S3 Backend no valid credential sources for S3 Backend found?
- Terraform state locking using DynamoDB (aws_dynamodb_table)?
- Managing Terraform states?
- Securing AWS secrets using HashiCorp Vault with Terraform?
- How to use Workspaces in Terraform?
- How to run specific terraform resource, module, target?
- How Terraform modules works?
- Secure AWS EC2s & GCP VMs with Terraform SSH Keys!
- What is terraform provisioner?
- Is terraform destroy needed before terraform apply?
- How to fix terraform error Your query returned no results. Please change your search criteria and try again?
- How to use Terraform Data sources?
- How to use Terraform resource meta arguments?
- How to use Terraform Dynamic blocks?
- Terraform - How to nuke AWS resources and save additional AWS infrastructure cost?
- Understanding terraform count, for_each and for loop?
- How to use Terraform output values?
- How to fix error configuring Terraform AWS Provider error validating provider credentials error calling sts GetCallerIdentity SignatureDoesNotMatch?
- How to fix Invalid function argument on line in provider credentials file google Invalid value for path parameter no file exists
- How to fix error value for undeclared variable a variable named was assigned on the command line?
- What is variable.tf and terraform.tfvars?
- How to use Terraform Variables - Locals,Input,Output
- Terraform create EC2 Instance on AWS
- How to fix Error creating service account googleapi Error 403 Identity and Access Management (IAM) API has not been used in project before or it is disabled
- Install terraform on Ubuntu 20.04, CentOS 8, MacOS, Windows 10, Fedora 33, Red hat 8 and Solaris 11