Switching between different/multiple terraform versions
2022, Jun 06
Prerequisites
This can be achieved with an OS tool called tfenv
Currently tfenv supports the following OSes
- Mac OS X (64bit)
- Linux ( 64bit and Arm )
- Windows (64bit) - only tested in git-bash - currently presumed failing due to symlink issues in git-bash
Install tfenv via Homebrew for MacOS
brew install tfenv
How to use
Check if tfenv is properly installed
tfenv version
Pick the terraform version you want and use the tfenv install command :
List remotes :
tfenv list-remote
As alternative, for checking available terraform versions you can check the list in here :
https://releases.hashicorp.com/terraform /
tfenv install 0.15.1
Use the terraform version you’ve just installed
tfenv use 0.15.1
Check that proper terraform version is used
terraform --version
List all currently installed terraform versions :
tfenv list
For windows (git-bash):
Check out tfenv into any path (here is ${HOME}/.tfenv)
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
Add ~/.tfenv/bin to your $PATH any way you like
$ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
OR you can make symlinks for tfenv/bin/* scripts into a path that is already added to your $PATH (e.g. /usr/local/bin) OSX/Linux Only!
ln -s ~/.tfenv/bin/* /usr/local/bin
On Ubuntu/Debian
Touching /usr/local/bin might require sudo access, but you can create ${HOME}/bin or ${HOME}/.local/bin and on next login it will get added to the session $PATH or by running . ${HOME}/.profile it will get added to the current shell session’s $PATH.
mkdir -p ~/.local/bin/
. ~/.profile
ln -s ~/.tfenv/bin/* ~/.local/bin
which tfenv
Links :
https://github.com/tfutils/tfenv