AndyHunt.me

CV and personal site of Andy Hunt

Go has a built-in version manager

Posted: Tuesday 23 February 2021 @ 14:14:21

Most (if not all) languages I use day to day require me to have multiple versions installed, to support the different projects/code bases. Tools like rbenv, tfenv, and nvm are really good at managing versions for their respective languages, but Go appeared to be lacking anything like that.

I've tried to use goenv but it hasn't been updated since June 2019 at the time of writing. Other tools like gvm are similarly unloved.

Today I learned that Go has a built-in way of installing multiple versions of the language.

Without rehashing what the documentation already says, it allows you to install Go versions as a binary named go${version} (e.g. go1.15), whose SDK lives at ~/sdk/go${version}.

The binary is installed in both the SDK path, and the $GOBIN path (usually ${GOPATH}/bin/). To manage the default version, I can create a symlink in my path to the Go binary I want to use:

$ ln -s ~/sdk/go1.15/bin/go /usr/local/bin/go

It's not perfect, but it does the job, and it's easy to install and maintain other versions. If I want to use a specific version, and I have $GOBIN in my path, I can execute it as (for example) go1.15 version.

$ which go1.15
/Users/andyhunt/code/bin/go1.15
$ go1.15 version
go version go1.15 darwin/amd64