How to install Terraform in Ubuntu

Solution 1:

Steps to install terraform on Ubuntu / Ubuntu cloud server :

  1. Install unzip

    sudo apt-get install unzip
    
  2. Confirm the latest version number on the terraform website:

    https://www.terraform.io/downloads.html
    
  3. Download latest version of the terraform (substituting newer version number if needed)

    wget https://releases.hashicorp.com/terraform/1.0.7/terraform_1.0.7_linux_amd64.zip
    
  4. Extract the downloaded file archive

    unzip terraform_1.0.7_linux_amd64.zip
    
  5. Move the executable into a directory searched for executables

    sudo mv terraform /usr/local/bin/
    
  6. Run it

    terraform --version 
    

Solution 2:

If you’re running Ubuntu plus snap installed, just call:

sudo snap install terraform

Solution 3:

What about using Terraform official deb repository, you can than install and update Terraform using apt.

https://www.terraform.io/docs/cli/install/apt.html#repository-configuration

Like this:

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt update
sudo apt install terraform

Solution 4:

My one-liner to install the latest version:

sudo echo ; zcat <( CURRR_VER=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version') ; curl -q "https://releases.hashicorp.com/terraform/${CURRR_VER#?}/terraform_${CURRR_VER#?}_linux_amd64.zip" ) | sudo tee /usr/local/bin/terraform > /dev/null ; sudo chmod +x /usr/local/bin/terraform

Using the line from https://github.com/hashicorp/terraform/issues/9803#issuecomment-257903082