May 3, 2023 5 min read

Installing Terraform to Linux (with a Binary Download)

Table of Contents
⚠️
If you haven't already, I recommend checking out this article first about installing Terraform on Linux via package manager.

In a previous post, I showed how to install Terraform on Linux by way of package manager. While that is a decent method and a best practice for beginners, there are other methods of installation: for example, from binary.

Using the binary version of Terraform is very common in the field. To use it, you simply have to download the binary, unzip it, and place it in your binaries directory. Easy!

💡
But there are a couple of important concepts that you might also want to incorporate: for example, checksum verification and scripting to automate the installation of Terraform. We'll touch on those as we work toward our goal of installing Terraform from binary.

Check out the short video below to see a demonstration of this and read on for the step-by-step process.

Video


Installation Instructions

The step-by-step instructions below will demonstrate how to download the Terraform binary, verify its checksum, unzip it, and move it to the binaries directory. (You can use the same procedure for any HashiCorp products: Vault, Consul, and so on.)

🗒️
It's a good idea to work in a temporary directory. This can be one that you create within your home directory or can be /tmp. For this procedure, I am making a directory named temp inside of my home directory. So in this case the path would be ~/temp.

To download the latest version of Terraform (or older versions) go to:

https://releases.hashicorp.com/terraform

Download the file

Access the required version (usually the latest) and locate the download for your platform. You will find a lot of options based on OS and computer hardware.

In the video, I am installing to a Debian Linux system that runs within a virtual machine on a PC. In this instance I need the following:

terraform_<version>_linux_amd64.zip

You can either download the zip file simply by clicking it, or you could right-click it, select Copy Link, and then paste that link into the terminal (or into a script). For this procedure, we'll use the terminal. You can either use the wget command or the curl command.

  • Using wget:

wget <http_URL>

That is the easiest option. That will grab the zip file and place it in your current directory.

  • Using curl:

curl -Lo /tmp/terraform.zip <http_URL>

This option will download the zip file, rename it, and place it in the /tmp directory (if you have one).

🗒️
Often, curl is used in automated scripts. If you were to use the curl command in a script, then you would most likely also want the -s option to make the command silent.

Verify the checksum of the file

Now verify the checksum of the file. We'll use sha256sum. This should be installed on your Linux client by default.

First, download the SHA256SUMS file.

Next, run the cat command on the checksum file. This will return the checksums for all downloads for that particular version of Terraform.

cat terraform_<version>_SHA256SUMS

Now, verify the checksum of the downloaded .zip file.

sha256sum <filename.zip>

The checksum should match the one listed in the SHA256SUMS file. If so, move to the next step. If not, do not use the file and instead delete it. You would need to investigate further as to why the checksums don't match.

Rename and unzip the file

Rename the zipped file to terraform.zip.

mv <filename.zip> terraform.zip

Unzip the file

unzip terraform.zip

This should unzip the archive and place a file named terraform in your working directory.

Move the file

Now, move the unzipped file to the binaries directory:

mv terraform /usr/bin

🔷
The path to the binaries directory in your version of Linux might be different. For example: /usr/local/bin, so be ready for minor differences from one distro to the next. In reality, you could store it wherever you want, but the Terraform command won't work unless you add it to your list of paths ($PATH). For example:

export PATH="/usr/bin:$PATH"

This method also works for macOS. However, for Windows, you would need to move the file to the C:\Program Files folder and then include Terraform in your path. But I digress...

Test your installation

At this point, you should be able to use the terraform command. Test it:

terraform version

You should see results similar to this:

dave@pt1:~/temp$ terraform version
Terraform v1.4.6
on linux_amd64

Here we are running Terraform version 1.4.6. Your version will most likely be newer. But as long as you see a version number, you know that Terraform is working.

That's it! You now have a working installation of Terraform.

🍵
You will find that using curl is an excellent method for scripting automated installations of Terraform on remote hosts. But this is only one method. While the Bash method is great—keep in mind that there are lots of other automation tools available to you (Ansible, cloud-init, and so on...)

Excellent work! Thanks for reading!

🌎 Terraform Video Course

It's finally published! The HashiCorp Certified Terraform Associate (003) video course is ready for viewing on InformIT & O'Reilly*. Check it out at the links below.

InformIT

HashiCorp Certified Terraform Associate (003) (Video Course) | InformIT
12+ Hours of Video Instruction Learn how to use Infrastructure as Code Using Terraform. HashiCorp Certified Terraform Associate (003) is your full resource to successfully study for this popular exam. With over 12 hours of training, you get comprehensive coverage of all exam objectives outlined by H…

Enter the DPRO discount code to receive 70% off!

O'Reilly*

HashiCorp Certified Terraform Associate (003)
19+ Hours of Video Instruction Learn how to use Infrastructure as Code Using Terraform. HashiCorp Certified Terraform Associate (003) is your full resource to successfully study for this popular exam. … - Selection from HashiCorp Certified Terraform Associate (003) [Video]

* A subscription to the O'Reilly platform is required.


Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Prowse Tech.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.