Since there are many projects to maintain, and since these projects have different histories, some may be written by myself, some may be taken over from others, one of the problems I am facing is that Go versions may not be consistent, but you dare not take the risk to upgrade to a consistent version, after all, the test coverage is not enough to give me confidence to do so.
So, for now, I’m sticking with the Go version specified by the project, so I have the need to use multiple Go versions locally. This article is about the Mac environment, but it should actually work in the Linux environment as well.
Managing multiple environments via brew
[[email protected].io]# brew install go # 1.17
[[email protected].io]# brew install [email protected].15
[[email protected].io]# brew unlink go
[[email protected].io]# brew link [email protected].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.
[[email protected].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 can also help you download.
|Figure 1：Open Setting|
|Figure 2：Choose Go Version|
If you think that’s not enough, then you can ask Goland to download one for you：
|Figure 3：Download Button|
|Figure 4：Select Version|
Various versions for you to choose from.
However, don’t forget to select a different GOPATH after switching Go versions as well：
|Figure 5：Setup GOPATH|