📚

WSL2にtfenv環境をインストールする手順

2022/12/14に公開約3,200字

Gitからtfenvをクローンします

root@localhost:~# git clone https://github.com/tfutils/tfenv.git ~/.tfenv
Cloning into '/root/.tfenv'...
remote: Enumerating objects: 1959, done.
remote: Counting objects: 100% (564/564), done.
remote: Compressing objects: 100% (147/147), done.
remote: Total 1959 (delta 464), reused 444 (delta 413), pack-reused 1395
Receiving objects: 100% (1959/1959), 414.93 KiB | 1.01 MiB/s, done.
Resolving deltas: 100% (1268/1268), done.
root@localhost:~# 

環境変数を設定します

root@localhost:~# echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
root@localhost:~# source ~/.bash_profile

インストール可能なTerraformのバージョンを確認

root@localhost:~# tfenv list-remote
1.4.0-alpha20221207
1.4.0-alpha20221109
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
~略~
root@localhost:~#

現在インストールされているTerraformのバージョンを確認する

現在はまだ利用できるバージョンがありません。

root@localhost:~# tfenv list
No versions available. Please install one with: tfenv install

Terraform 1.3.6をインストールしてみる

root@localhost:~# tfenv install 1.3.6
Installing Terraform v1.3.6
Downloading release tarball from https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_linux_amd64.zip
################################################################################################################# 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_SHA256SUMS
Not instructed to use Local PGP (/root/.tfenv/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /tmp/tfenv_download.QtiAR5/terraform_1.3.6_linux_amd64.zip
  inflating: /root/.tfenv/versions/1.3.6/terraform
Installation of terraform v1.3.6 successful. To make this your default version, run 'tfenv use 1.3.6'

1.3.6を利用するよう設定する

root@localhost:~# tfenv use 1.3.6
Switching default version to v1.3.6
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.3.6

バージョン確認

root@localhost:~# terraform  -v
Terraform v1.3.6
on linux_amd64

他のバージョンもインストールしてみる

root@localhost:~# tfenv install 1.2.9
Installing Terraform v1.2.9
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.9/terraform_1.2.9_linux_amd64.zip
################################################################################################################# 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.9/terraform_1.2.9_SHA256SUMS
Not instructed to use Local PGP (/root/.tfenv/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /tmp/tfenv_download.DWqXLc/terraform_1.2.9_linux_amd64.zip
  inflating: /root/.tfenv/versions/1.2.9/terraform
Installation of terraform v1.2.9 successful. To make this your default version, run 'tfenv use 1.2.9'

バージョンを切り替える

root@localhost:~# tfenv use 1.2.9
Switching default version to v1.2.9
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.2.9

バージョンが変更されたことを確認する

root@localhost:~# terraform  -v
Terraform v1.2.9
on linux_amd64

Your version of Terraform is out of date! The latest version
is 1.3.6. You can update by downloading from https://www.terraform.io/downloads.html
root@localhost:~#

Discussion

ログインするとコメントできます