Perform multiple version control of Go with anyenv + goenv

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.

What is goenv

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.

What is anyenv

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


Install anyenv

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

Install goenv using anyenv and restart the shell.

% anyenv install goenv
% exec $SHELL -l

Install Go

Check the version that can be installed.

% goenv install -l
Available versions:

Specify the desired version and install.

% goenv install 1.15.6

Execute the following command to display the list of installed versions.

% goenv versions

Base version specification

% goenv global 1.15.6
% go version
go version go1.15.6 darwin/amd64

1.15.6 is now the default go version.

Specify version in directory

If you want to use Go v1.14.13 in the ~/sample directory

% cd ~/sample
% goenv local 1.14.13
% go version
go version go1.14.13 darwin/amd64

goenv update

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.

Recommended Posts

Perform multiple version control of Go with anyenv + goenv
Version control of Node, Ruby and Python with anyenv
[Gvm] Go version control
Control multiple robots with jupyter-lab
Install GoLang in goenv of anyenv
I tried to make a mechanism of exclusive control with Go
Summary of snippets when developing with Go
[MacOS] Installation of Go (Go language) using goenv
Hello world with full features of Go language
Use multiple versions of python environment with pyenv
Automatic version sync of chrome driver binary with chrome