When developing in Go language, it often happens that you want to use multiple versions locally, so as a countermeasure, I will introduce a method to make it easy to switch versions using goenv and anyenv.
A Go version control tool modeled after pyenv and rbenv. By using this, you can switch versions, change the version for each Go development project, switch the version of Go with environment variables, and so on.
~ A tool that manages env tools. In addition to the goenv, pyenv, and rbenv mentioned above, you can control version control tools for various languages such as nodenv and tfenv. Since this article deals only with Go, it is okay without anyenv, but I will introduce it together considering the possibility of version control of other languages in the future.
If you have Homebrew installed, install it with the following command.
% brew install anyenv
Set up anyenv on your shell.
% anyenv init
Relaunch the shell to apply the setup. (Just close it and open a new terminal)
Install goenv using anyenv and restart the shell.
% anyenv install goenv % exec $SHELL -l
Check the version that can be installed.
% goenv install -l Available versions: 1.2.2 . . . 1.15.6 1.16beta1
Specify the desired version and install.
% goenv install 1.15.6
Execute the following command to display the list of installed versions.
% goenv versions
% goenv global 1.15.6 % go version go version go1.15.6 darwin/amd64
1.15.6 is now the default go version.
If you want to use Go v1.14.13 in the
% cd ~/sample % goenv local 1.14.13 % go version go version go1.14.13 darwin/amd64
If you don't see it with
goenv install -l when a new version of Go is released, you need to update goenv.
% anyenv install goenv anyenv: /Users/xxxxx/.anyenv/envs/goenv already exists Reinstallation keeps versions directories continue with installation? (y/N)Enter y ← y
After restarting the shell, the version of Go available in goenv should be up to date.