terraform-switcher: should not require root or -b when switching
By default tfswitch assumes current user can write to /usr/local/bin. If this is not true, then you only have 2 options, neither of them are nice:
- every time you want to switch terraform version, you have to
sudo tfswitchAND thereafter you have tosudo terraformbecause when yousudo tfswitchthe location of terraform files ends up being root. You could of course dosudo tfswitch -b /usr/local/bin/tfswitchesbut then you would have to alias this in your .bashrc - every time you want to switch terraform version, you have to
tfswitch -b some/path/to/terraformAND yourPATHenv var must containsome/path/to, which requires creating the folder, editing editing .bashrc to extend the path; and since no one wants to be entering the path everytime, you have to create an alias
It does not appear to be possible to use the .tfswitch.toml file to capture bin location as this requires a version (or applies only to the current version)
The default location of terraform should be the user’s $HOME/bin. The tfswitch would just work with only the need to add $HOME/bin to path in .bashrc.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 16 (3 by maintainers)
@amine250
The only one that satisfies this is user’s home directory.
That’s really what should be the default anyways: rarely would every user of a system want to use the same version of terraform.
I think
$HOME/.local/binis the standard location for user-specific installs. See eg the answers inWith the latest release, tfswitch will automatically attempt to use $HOME/bin. You don’t need to use the
-boption. Download the latest release (>0.12.1168) to test it out. Please let me know if you find any bugs. Thanks.$HOME/binmakes total sense, I just want to add that I am setting up a new Big Sur machine and$HOME/binis not part of the default$PATH. I thought that was a bit odd, but I can’t remember if it was like that on previous OSX versions.I’ve not heard of
$HOME/.local/bin, but the same would apply, you’d have to explicitly add it to the path. Of the choices I have to agree that$HOME/binis the least surprising.Thanks, I’ll try it out asap. It should also be mentioned in the README that the $HOME/bin should be in the PATH (if it’s not already mentioned).