Go Version Management
There is a better alternative, please see
<<VSC Developing inside a Container>>.
This post talks about how to install multiple go binaries in the same machine and switch back and forth easily.
You may need a primary go version for daily work. Download and install go for different operating system from here:
The instruction will put the download to /usr/local/go, for multi-version
install below, they are downloaded to different folder so there is no conflict.
If you need to install other go versions in the same machine:
First, there are 2 go env variables involved:
GOROOTis for compiler/tools.GOPATHis for your own go projects and 3rd party libraries (downloaded withgo get/install).
You can check their value by:
1 | go env GOROOT |
The go install location is controlled by the GOBIN and GOPATH environment
variables depends their existence, in the order:
- If
GOBINis set, binary is installed at that directory. - If
GOPATHis set, binary is installed at thebinsubdirectory of the first path in theGOPATHlist, otherwise binary is installed to the bin subdirectory of the defaultGOPATH($HOME/go).
1 | go install golang.org/dl/go1.10.7@latest |
Go to $GOPATH/bin to find the downloaded object and run:
1 | go1.10.7 download |
From output, 1.10.7 version go binary will be downloaded to $GOPATH/../sdk
folder.
To use the downloaded version, we can update the PATH environment variable:
1 | export PATH=/usr/local/google/home/<user>/sdk/go1.10.7/bin:$PATH |
NOTE that if there are many go versions, must set the target go bin path at the beginning of
PATH, theGOROOTwill be automatically set according to first go bin in thePATH.
Then verifying by running:
1 | # go version |
To recover original setting, just revert the PATH environment variable.