Cyberithub

How to Install and Use tfenv (Terraform version manager) on macOS

Advertisements

In this article, we will see how to install and use tfenv (terraform version manager) on macOS. tfenv is a free and open source tool used for installing and managing multiple terraform versions. Using tfenv, you can switch to a terraform version and use it as and when needed. It allows developers to test and build modules for different terraform versions hence eliminating the overhead of uninstalling the previous versions to install a new one, everytime developer need a specific version.

tfenv uses .terraform-version file saved in project root directory to detect the terraform version to use. If the version is latest or latest:<regex>, the latest matching version currently installed will be selected. It is super easy to install and use in almost all the famous platforms such Windows, Linux and Mac. Here we will see the steps to install and use tfenv (Terraform version manager) on macOS.

 

How to Install and Use tfenv (Terraform version manager) on macOS

How to Install and Use tfenv (Terraform version manager) on macOS

Also Read: How to Install kubefwd on macOS Using 6 Easy Steps

Step 1: Prerequisites

a) You should have a running macOS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have brew utility installed in your Server.

 

Step 2: Update Your Server

Before installing a new formulae, it is required to update all the existing ones by using brew update command as shown below.

cyberithub@macos1066 ~ % brew update

 

Step 3: Install tfenv

Once all the formulae are updated to the latest versions, you can now install tfenv by using brew install tfenv command as shown below.

cyberithub@macos1066 ~ % brew install tfenv
==> Downloading https://ghcr.io/v2/homebrew/core/tfenv/manifests/3.0.0
Already Downloaded: /Users/cyberithub/Library/Caches/Homebrew/downloads/85084ahh39rhslffo93hrfbekdhjdfjhkhdefllfjke--tfenv-3.0.0.bottle_manifest.json
==> Fetching dependencies for tfenv: grep
==> Downloading https://ghcr.io/v2/homebrew/core/tfenv/manifests/3.11
Already Downloaded: /Users/cyberithub/Library/Caches/Homebrew/downloads/e05822719ahh39rhslffo93hrfbekdhjdfehkhdefllfjke--grep-3.11.bottle_manifest.json
==> Fetching grep
==> Downloading https://ghcr.io/v2/homebrew/core/grep/blobs/sha256:e66f574ad567da8eddac56797bdd435a34f65eab678
Already Downloaded: /Users/cyberithub/Library/Caches/Homebrew/downloads/e05822719a239cee78be93abfbecd3edfbdacdef35e23e--grep--3.11.monterey.bottle.tar.gz
==> Fetching tfenv
==> Downloading https://ghcr.io/v2/homebrew/core/tfenv/blobs/sha256:4905c2390b0e66f574ad567da8eddac56797bdd435a34f65eab678
Already Downloaded: /Users/cyberithub/Library/Caches/Homebrew/downloads/8be822719a8dc39rhslffa93hrfbe5d3adfe9ahdefd34f28e--tfenv--3.0.0.all.bottle.tar.gz
==> Installing dependencies for tfenv: grep
==> Installing tfenv dependency: grep
==> Downloading https://ghcr.io/v2/homebrew/core/grep/manifests/3.11
Already Downloaded: /Users/cyberithub/Library/Caches/Homebrew/downloads/28abd5822719ahh39rhsldao93hrfbekdhadfea89hdefllfa7e--grep-3.11.bottle_manifest.json
==> Pouring grep--3.11.monterey.bottle.tar.gz
    /use/local/Cellar/grep/3.11: 19 files, 1MB
==> Installing tfenv
==> Pouring tfenv--3.0.0.all.bottle.tar.gz
    /usr/local/Cellar/tfenv/3.0.0: 28 files, 98.7KB
==> Running `brew cleanup tfenv`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
.............................................................

 

Step 4: Verify Installation

After successful installation, you can verify the working of utility by running tfenv command as shown below.

cyberithub@macos1066 ~ % tfenv
tfenv 3.0.0
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

 

Step 5: Install terraform using tfenv

Now that tfenv installed successfully, you can go ahead and install a specific version of terraform by using tfenv install <terraform_version> command. For example, if you are looking to install version 1.5.7 then you have to use tfenv install 1.5.7 command. If you would like to install the latest version of terraform then you can use tfenv install latest command as shown below.

cyberithub@macos1066 ~ % tfenv install latest
Installing Terraform v1.6.0
Downloading release tarball from https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_darwin_amd64.zip
#################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_SHA256SUMS
Not instructed to use Local PGP (/usr/local/Cellar/tfenv/3.0.0/use-{gpgv,gnupg} & No keybase install found, skipping OpenPGP signature verification
Archive: /var/folders/c4/1bhbmy092gzcnbktg334mry80000gp/T/tfenv_download.XXXXXX.N8P443TE/terraform_1.6.0_darwin_amd64.zip
  inflating: /usr/local/Cellar/tfenv/3.0.0/versions/1.6.0/terraform
Installation of terraform v1.6.0 successful. To make this your default version, run 'tfenv use 1.6.0'

 

Step 6: List all installed versions

After installing all the terraform versions, you can check the list of installed version by using tfenv list command as shown below. As you can see, currently we have installed the latest version only which is 1.6.0 so this is only one currently showing in the list. But if you have installed multiple versions then you should be able to see all of them in below list.

cyberithub@macos1066 ~ % tfenv list
  1.6.0
No default set. Set with 'tfenv use <version>'

 

Step 7: Switch a version to use

Once you have a specific version installed, you can use it by switching to that version using tfenv use <terraform_version> command. For example, here we are going to use version 1.6.0 by switching to it using tfenv use 1.6.0 command as shown below.

cyberithub@macos1066 ~ % tfenv use 1.6.0
Switching default version to v1.6.0
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.6.0

 

Step 8: Uninstall specific version of terraform

Similarly, if you would like to uninstall a specific version then you have to use tfenv uninstall <terraform_version> command. For example, here we are removing version 1.6.0 using tfenv uninstall 1.6.0 command as shown below.

cyberithub@macos1066 ~ % tfenv uninstall 1.6.0
Uninstall Terraform v1.6.0
Terraform v1.6.0 is successfully uninstalled

 

Step 9: Uninstall tfenv

Once you are done using tfenv, you can choose to uninstall it from your system by using brew remove tfenv command as shown below.

cyberithub@macos1066 ~ % brew remove tfenv
Uninstalling /usr/local/Cellar/tfenv/3.0.0... (29 files, 98.8KB)

Leave a Comment