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!
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.)
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).
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
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.
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
O'Reilly*