Overview

Because there are many projects to maintain, and because these projects have different histories, some may have been written by myself, some have been taken over from others, one of the problems we are facing is that Go versions may not be consistent, but you don’t dare to take the risk of upgrading to a consistent version, after all, the test coverage is not enough to give me confidence to do so.

So, for now, I’m going to stick with the Go version specified by the project. So there is a need to use multiple versions of Go locally. This article is about the Mac environment, but it should actually work in the Linux environment as well.

Manage multiple environments via brew

1
2
3
4
[root@liqiang.io]# brew install go  # 1.17
[root@liqiang.io]# brew install go@1.15
[root@liqiang.io]# brew unlink go
[root@liqiang.io]# brew link go@1.15

Specify a version to run the code

If you don’t want to set a global fixed version, you can also specify a path to run a different version.

But you need to be careful with the GOPATH environment variable. If you use the same GOPATH for different versions of Go, once the higher version updates the dependent libraries, the lower version won’t work, very important.

1
2
[root@liqiang.io]# GOPATH=/Users/liqiang.io/Applications/srcs/gopath1.14 \
            /Users/liqiang.io/Applications/srcs/go1.14.6/bin/go test cmd/server/main*

Goland sets up multiple versions

Goland supports different versions of Go by default, and it can also download them for you.

Open Settings

Select the version of Go

If you think that’s not enough, then you can ask Goland to download one for you.

Version selection

Various versions are available for you to choose from.

GOPATH

However, don’t forget to select a different GOPATH after switching Go versions as well.

Setting up GOPATH