Installing multiple Golang versions

macOS 10.14 Mojave
Golang 1.11

Hello, I am running Go 1.11 but I have tried to install https://github.com/icexin/gocraft and am having some issues with it. The author has asked me if it works with Go 1.10, so my question is: how do I install 1.10 alongside 1.11 in as painless (ie. avoiding building from source) a way as possible?

I’ve tried searching but have only found old solutions that involve building from source.

Have you tried asdf + asdf-golang?

I’ve just installed asdf and asdf-golang and they seemed to install okay. Trouble is that having installed them it is not at all obvious how to use them, and the documentation seems to be missing this vital bit of information, unless I’m missing something glaringly obvious.

Any clues?

1.10 is easy, you can get it with:

go get golang.org/x/build/version/go1.10.3

You will end up with a binary go1.10.3 that will give you access to go1.10.3. The first time you run it, it will ask you to run go1.10.3 download to download the binary distribution for your platform. After that just use go1.10.3 instead of go when you need that version.

To learn more about how this works, read my article Trying Other Go Versions.

1 Like

Basically is easiest to work with multiple Go versions by putting them in your $HOME folder. On your Mac system you must have a file .bash_profile in your $HOME folder. Put there the following content:

GOROOT=${HOME}/go
GOPATH=${HOME}
PATH=$PATH:/${GOROOT}/bin:${GOPATH}/bin
export PATH GOPATH GOROOT

GOROOT is the path to your current Go compiler. Adjust GOPATH as you need.
Now, download various compilers from https://golang.org/dl/. Unarchive and remember to add the version to the name (eg. go1.11, go 1.10). Then, switch the current version from .bash_profile GOROOT variable eg.

GOROOT=${HOME}/go1.10

Note that you must reopen the terminal after each modifying of .bash_profile to work.
:sunglasses:

1 Like

You don’t need to reopen the terminal. Just use either of these commands, which do the same thing:

. ~/.bash_profile
source ~/.bash_profile

1 Like

Thanks Nathan, I knew I had seen something like this before. I just couldn’t remember the details. I’ve uninstalled asdf. Sadly the package in question still doesn’t work with go 1.10.3 but at least I can switch easily between versions now. It also provides me with an easy way of switching between a GO111MODULE=on and GO111MODULE=off environment. I’ve now go an alias goo (short for go old) for go1.10.3!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.