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:

  1. every time you want to switch terraform version, you have to sudo tfswitch AND thereafter you have to sudo terraform because when you sudo tfswitch the location of terraform files ends up being root. You could of course do sudo tfswitch -b /usr/local/bin/tfswitches but then you would have to alias this in your .bashrc
  2. every time you want to switch terraform version, you have to tfswitch -b some/path/to/terraform AND your PATH env var must contain some/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)

Most upvoted comments

@amine250

find a directory that’s in the PATH of most of OSs and that’s also writable by the normal user.

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.

With the latest release, tfswitch will automatically attempt to use $HOME/bin. You don’t need to use the -b option. Download the latest release (>0.12.1168) to test it out. Please let me know if you find any bugs. Thanks.

1. For linux users that do not have write permission to `/usr/local/bin/`, `tfswitch` will attempt to install terraform at `$HOME/bin`. Run `export PATH=$PATH:$HOME/bin` to append bin to PATH  
2. For windows host, `tfswitch` need to be run under `Administrator` mode, and `$HOME/.tfswitch.toml` with `bin` must be defined (with a valid path) as minimum, below is an example for `$HOME/.tfswitch.toml` on windows

With the latest release, tfswitch will automatically attempt to use $HOME/bin. You don’t need to use the -b option. Download the latest release (>0.12.1168) to test it out. Please let me know if you find any bugs. Thanks.

1. For linux users that do not have write permission to `/usr/local/bin/`, `tfswitch` will attempt to install terraform at `$HOME/bin`. Run `export PATH=$PATH:$HOME/bin` to append bin to PATH  
2. For windows host, `tfswitch` need to be run under `Administrator` mode, and `$HOME/.tfswitch.toml` with `bin` must be defined (with a valid path) as minimum, below is an example for `$HOME/.tfswitch.toml` on windows

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).

$HOME/bin makes total sense, I just want to add that I am setting up a new Big Sur machine and $HOME/bin is 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/bin is the least surprising.

With the latest release, tfswitch will automatically attempt to use $HOME/bin. You don’t need to use the -b option. Download the latest release (>0.12.1168) to test it out. Please let me know if you find any bugs. Thanks.

1. For linux users that do not have write permission to `/usr/local/bin/`, `tfswitch` will attempt to install terraform at `$HOME/bin`. Run `export PATH=$PATH:$HOME/bin` to append bin to PATH  
2. For windows host, `tfswitch` need to be run under `Administrator` mode, and `$HOME/.tfswitch.toml` with `bin` must be defined (with a valid path) as minimum, below is an example for `$HOME/.tfswitch.toml` on windows

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).