tfenv works like nvm for Node.js — it lets you install and switch between Terraform versions easily.
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
Update zshrc
export PATH=$PATH:/snap/bin:~/bin:~/.local/bin:~/.pyenv/bin:$HOME/.tfenv/bin
tfenv install 1.8.5
➜ ~ tfenv install 1.8.5
Installing Terraform v1.8.5
Downloading release tarball from https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_amd64.zip
##################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_SHA256SUMS
Not instructed to use Local PGP (/home/yangy9/.tfenv/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive: /tmp/tfenv_download.5vM1kH/terraform_1.8.5_linux_amd64.zip
inflating: /home/yangy9/.tfenv/versions/1.8.5/LICENSE.txt
inflating: /home/yangy9/.tfenv/versions/1.8.5/terraform
Installation of terraform v1.8.5 successful. To make this your default version, run ‘tfenv use 1.8.5’
tfenv use 1.8.5
➜ ~ which terraform
/home/myusername/.tfenv/bin/terraform
terraform –version
Terraform v1.8.5