57

I'm start using Terraform and I'm following the project updates on his Github repository.

I see new releases are available on releases section: https://github.com/hashicorp/terraform/releases

I installed Terraform tool following the steps: https://www.terraform.io/intro/getting-started/install.html

The new releases are a zip file with base code but I want to know how I can install it on my computer (OSX). What I downloaded when I installed for the first time was a zip file with just a "terraform" file as unix executable.

How I can generate this Unix executable from the zip available on the github releases section?

Any idea?

Thank you!

Borja Lopez
  • 579
  • 1
  • 4
  • 4

11 Answers11

75

If you use Homebrew on MacOS already, you can install Terraform simply by

$ brew install terraform

and upgrade by

$ brew upgrade terraform

In fact, you might be interested in letting Homebrew also control other tools:

$ brew install awscli
$ brew install packer
$ brew cask install docker
$ brew cask install virtualbox
$ brew cask install vagrant
jpsecher
  • 4,461
  • 2
  • 33
  • 42
  • 9
    You can then also use 'brew switch' to switch between multiple versions if you are working on different projects. e.g. `brew switch terraform 0.10.2` more info here: https://stackoverflow.com/questions/13477363/how-can-i-brew-link-a-specific-version – Matt Childs Sep 04 '17 at 11:39
  • @JP will this work for beta releases as well ? recently the have given a beta release v0.13.0-beta3 and i was thinking if brew upgrade terraform will work for beta version as well.? – codeaprendiz Jul 09 '20 at 09:09
  • @codeaprendiz Yes, it will work *if* the beta version has been bottled. RIght now it seems that it hasn't: `brew search /^terraform@.+$/` – jpsecher Jul 10 '20 at 11:22
  • Thanks @JP, so how can i try it on my local ? :) ... i actually want to try the new features. – codeaprendiz Jul 10 '20 at 11:27
13

There are packages for each OS available on the Downloads Page.

  1. Pick the appropriate package for your OS and download the zip file.
  2. Extract the contents of the zip file, which should be a single terraform binary, into some reasonable location that's in your PATH (e.g. /usr/local/bin).
  3. Add execute permissions: e.g. chmod u+x /usr/local/bin/terraform.
  4. Run terraform and make sure you see the help text.
Yevgeniy Brikman
  • 8,711
  • 6
  • 46
  • 60
  • First of all, thank you for your reply Yevgeniy. Now the last release from releases section at Github repository is available at [link] (https://www.terraform.io/downloads.html) `Downloads Page`. But for several days it wasn't at that link and I was looking for the way to get the code from Github release and generate the `terraform` binary file. – Borja Lopez Nov 30 '16 at 10:19
  • 1
    @BorjaLopez if the answer helped, would you mind accepting it? Thanks. – Radek Simko Feb 14 '17 at 10:10
12

You could download the binary :

wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip

then :

unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip

then :

mv terraform /usr/local/bin/

make sure to change ${TERRAFORM_VERSION} by the version you want to install

exemple :

0.13.2
Montassar Bouajina
  • 1,482
  • 1
  • 8
  • 20
9

**TLDR:

  • for Installation - brew install terraform
  • for Upgrade - brew upgrade terraform
  • for Verification - terraform --version
avivamg
  • 12,197
  • 3
  • 67
  • 61
8

i'm new to using terraform, but to use terraform with multiple versions i use tfenv as terraform version manager

tfenv command

$ tfenv
tfenv 2.2.3
Usage: tfenv <command> [<options>]

Commands:
   install       Install a specific version of Terraform
   use           Switch a version to use
   uninstall     Uninstall a specific version of Terraform
   list          List all installed versions
   list-remote   List all installable versions
   version-name  Print current version
   init          Update environment to use tfenv correctly.
   pin           Write the current active version to ./.terraform-version

terraform currently i use

$ terraform -version                                                                                         
Terraform v1.1.9
on linux_amd64

list of terraform i have

$ tfenv list                                                                                                   
  1.2.0-rc2
* 1.1.9 (set by /home/takimi/.tfenv/version)

change terraform version

$ tfenv use 1.2.0-rc2

and if you want to use another terraform version you just install it with command tfenv install <terraform version>

khilmi aminudin
  • 117
  • 1
  • 4
6

Adding this response for the sake of completeness.

Hashicorp came up with their own brew taps for all Hashicorp products for MacOS platforms.

to upgrade ...

brew upgrade hashicorp/tap/{vault|consul|nomad|terraform|packer}

to install ...

brew install hashicorp/tap/{vault|consul|nomad|terraform|packer}

Reference : https://www.hashicorp.com/blog/announcing-hashicorp-homebrew-tap

Naveen Vijay
  • 15,928
  • 7
  • 71
  • 92
  • 2
    If i could i would change this to the correct accepted answer into 2020 and beyond. `brew install terraform` simply gets it from the community, so you're not going to get the 1.0 release that came out this week until someone puts in the work. IMO, the community version should be removed. Only b/c it can keep you from features that are available immediately after HasiCorp releases a fix. I appreciate peoples work on the community version, just my opinion. – ekydfejj Jun 09 '21 at 21:44
2

This is detailed in the repository README under 'Developing Terraform' HERE

Essentially...

  1. Ensure you've installed the GO programming language (version 1.7+ at the time of writing).
  2. Create a GO workspace directory.
  3. Create the $GOPATH environment variable pointing to the GO workspace directory you just created.
  4. Add $GOPATH/bin to your $PATH
  5. Clone the Terraform repo (or extract zip) to $GOPATH/src/github.com/hashicorp/terraform
  6. Run make dev within the Terraform repo.
  7. The Terraform binary should be created in $GOPATH/bin

I would recommend you follow the steps in the README as opposed to what I've written above it's comprehensive and may change.

You shouldn't need to do any of this unless your actively developing Terraform, otherwise stick with the installation method in the getting started guide.

Chris
  • 21
  • 4
2

To work with multiple Terraform versions, I'm using tfswitch. This allows you to switch between the terraform versions which makes things much easier.

You can find the documentation here.

Krishan Thisera
  • 521
  • 4
  • 5
1

I was able to use this tool to manage terraform versions: https://github.com/Zordrak/tfenv. The first step was to remove the existing installation with: rm '/usr/local/bin/terraform'

Bwyss
  • 1,736
  • 3
  • 25
  • 48
0

You could use something like asdf or tfenv to manage the terraform binaries.

Gives you the advantage of having the option to use different version per project if required.

Alastair Montgomery
  • 1,756
  • 5
  • 21
  • 44
0

$sudo apt-get upgrade it will work in linux if you have setup right path for terraform

  • you should format your answer. You can find more information on how to write good answers in the help center. – C.Vergnaud Oct 19 '21 at 14:20