Monday 21 March 2022

How to install Terraform on Ubuntu

We can install Terraform on Ubuntu in two ways:
  • downloading and installing a binary file
  • via package manager (apt)

Downloading and Installing a Binary

Terraform provides binaries that can be downloaded from Linux binaries are pre-compiled for the following architectures: 
  • 386
  • Amd64
  • Arm
  • Arm64
To find out your architecture use: 

$ uname -m

This means we're running on Amd64 architecture and so the binary we'll download is where M.m.r is the latest version. This version can be extracted from Terraform git repository tag:
$ TER_VER=`curl -s | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`
This is the latest Terraform version at the time of writing:

$ echo $TER_VER
We can use this variable in the following commands which download and unpack the archive and move the binary into bin directory accessible to all users on this machine:
$ wget${TER_VER}/terraform_${TER_VER}
$ unzip terraform_${TER_VER}
$ sudo mv terraform /usr/local/bin/

To test the installation:

$ terraform -v
Terraform v1.1.7
on linux_amd64

We can now delete the archive:
$ rm terraform_${TER_VER}
To uninstall Terraform:

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

Installing Terraform via Package Manager

To install Terraform via apt package manager we first need to add Hashicorp package source to our local package source list, update apt packages and then install terraform package. 

apt installs Terraform binary in this directory:

$ which terraform 

To uninstall Terraform:

$ sudo apt remove terraform



No comments: