What is the recommended approach for using multiple Go SDK versions?

781 views
Skip to first unread message

Adrian Sampaleanu

unread,
Feb 15, 2016, 1:34:10 PM2/15/16
to golang-nuts

Is there a recommended way to work with multiple SDK versions on one system? Would it be simply redefining GOROOT and GOPATH to point different locations as needed? I presume that trying to use the same GOPATH across multiple versions could result in a mess due to binary incompatibility in the pkg and bin directories, but maybe someone has a documented approach to dealing with this.

TIA for any suggestions/comments

 

Florin Patan

unread,
Feb 15, 2016, 8:31:46 PM2/15/16
to golang-nuts
In theory you need the following:
- wipe $GOPATH/pkg every time you switch between the Go version (might not be needed in the recent versions)
- set GOROOT for each command you run to point to the binary.

$GOPATH/bin is not important as those are binary executable files, the output of Bo install/build so not relevant for which Go version you use.

Hope this answers your question.

Dave Cheney

unread,
Feb 15, 2016, 8:44:01 PM2/15/16
to golang-nuts
It's even easier than that. Check out various versions of go into different locations,say $HOME/go1.4, $HOME/go1.5, build them as normal, then depending on which go command you invoke, it just works. You don't need to set GOROOT

Dave Cheney

unread,
Feb 15, 2016, 8:45:20 PM2/15/16
to golang-nuts
This blog post is 18 months old, so the methodology for building the code has changed, but the theory is still the same.

http://dave.cheney.net/2014/09/13/how-to-install-multiple-versions

Adrian Sampaleanu

unread,
Feb 16, 2016, 12:17:30 AM2/16/16
to golang-nuts

Thanks Florin, Dave - I'll take both of your comments into consideration give that I am using Windows and I do install from the zip file into a non-standard (c:\go) location.

Dave Cheney

unread,
Feb 16, 2016, 1:52:00 AM2/16/16
to golang-nuts
Hmm, in that case your options are less flexible. Compiling from source will give you all the flexibility that we enjoy on unix platforms, but it's a more complex process on windows. If you decide not to compile from source you will have to resort to changing %GOROOT% when you want to switch toolchains, and the possibility of getting that out of sync is likely. 

My recommendation would be to unpack the zip files into C:\, say c:\go1.5, c:\go 1.4, then "switching" Go versions is the same as renaming one of these folders to c:\go. That's going to be your most reliably method.
Reply all
Reply to author
Forward
0 new messages