tfenvはgithubにあります。

Linuxへのインストール

githubから取得します。

git clone https://github.com/tfutils/tfenv.git ~/.tfenv

環境設定にパスを指定します。

echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile

パスの設定が完了後、動作確認でヘルプを実行してみます。正常なら以下のようになります。

$ tfenv --help
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のインストール

tfenvを使用する場合、tfenv install コマンドでインストールできます。

tfenv install [バージョン]

$ tfenv install 1.0.8
Installing Terraform v1.0.8
Downloading release tarball from https://releases.hashicorp.com/terraform/1.0.8/terraform_1.0.8_linux_amd64.zip
######################################################################## 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.0.8/terraform_1.0.8_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
terraform_1.0.8_linux_amd64.zip: OK
Archive:  /tmp/tfenv_download.VFVY5n/terraform_1.0.8_linux_amd64.zip
  inflating: /home/vagrant/.tfenv/versions/1.0.8/terraform  
Installation of terraform v1.0.8 successful. To make this your default version, run 'tfenv use 1.0.8'

terraformのバージョン指定

インストール済みのバージョンを確認する場合、listコマンドを使います。

tfenv list

インストール済みのバージョンから、使用するバージョン番号を決めて、useコマンドで指定します。

tfenv use [バージョン]

例 バージョン 1.0.8 を使用するように設定

$ tfenv use 1.0.8
Switching default version to v1.0.8
Switching completed

設定後、listコマンドで確認すると、以下のようになります。

$ tfenv list
* 1.0.8 (set by /home/vagrant/.tfenv/version)