Managing multiple Go versions with direnv
https://direnv.net/docs/hook.html or allow prefix by setting up CAUTION: This allows execution of .envrc in all sub-directories.Install direnv
$ brew install direnv
Add to your shell
Create .envrc
GO={path to go version you want to use}
# If you use Homebrew
# GO=/opt/homebrew/Cellar/go@1.20/1.20.7/bin/go
export GOROOT="$($GO env GOROOT)"
PATH_rm '/opt/homebrew/Cellar/go*' # remove other versions
PATH_add "$($GO env GOROOT)/bin"
# use version specific GOPATH
export GOPATH=$HOME/go1.20
export PATH=$PATH:$GOPATH/bin
Allow .envrc
$ direnv allow
~/.config/direnv/direnv.toml
[whitelist]
prefix = ["{path to your workspace}"]