Install multiple versions of Go

  sonic0002        2021-05-16 02:01:46       5,622        0    

As a developer, there might be need in some cases to have multiple versions of Go installed. One may test out some new features of the latest version of Go but also wanna maintain a stable version of Go for daily development purpose. How to maintain multiple versions of Go?

The GoLang official website has provided a way to maintain multiple versions of Go by using go get to install the different versions of Go.

Below are steps:

  1. Download a normal version of Go and install it
  2. Go to the Go release page to find out which version of go to install
  3. Run the go get command to download the version and install it
    go get golang.org/dl/go1.16.4​
  4. Then run go[version] download to download and install it.
    C:\Users\pike6>go1.16.4 download
    Downloaded   0.0% (     3276 / 143991377 bytes) ...
    Downloaded   3.4% (  4915168 / 143991377 bytes) ...
    Downloaded  11.1% ( 15990096 / 143991377 bytes) ...
    Downloaded  18.9% ( 27230016 / 143991377 bytes) ...
    Downloaded  27.1% ( 39042208 / 143991377 bytes) ...
    Downloaded  35.3% ( 50773632 / 143991377 bytes) ...
    Downloaded  42.2% ( 60767808 / 143991377 bytes) ...
    Downloaded  49.8% ( 71728608 / 143991377 bytes) ...
    Downloaded  56.9% ( 82001296 / 143991377 bytes) ...
    Downloaded  65.0% ( 93649664 / 143991377 bytes) ...
    Downloaded  73.3% (105479392 / 143991377 bytes) ...
    Downloaded  80.9% (116456592 / 143991377 bytes) ...
    Downloaded  88.5% (127498752 / 143991377 bytes) ...
    Downloaded  96.8% (139361248 / 143991377 bytes) ...
    Downloaded 100.0% (143991377 / 143991377 bytes)
    Unpacking C:\Users\pike6\sdk\go1.16.4\go1.16.4.windows-amd64.zip ...
    Success. You may now run 'go1.16.4'​
  5. Next can run go[version] version to show the go installed successfully.
    C:\Users\pike6>go1.16.4 version
    go version go1.16.4 windows/amd64​
  6. To know why this go[version] would work, can just run which go[version[ and find the location where this binary is. Basically it will be put in the default go installation location.
    C:\Users\pike6>which go1.16.4
    /c/Users/pike6/go/bin/go1.16.4​

The issue with this is that to use different vesion of Go, the go command needs to be different.

There is another way to maintain multiple versions of Go is to use GVM which is similar to RVM. It's tool for Go version and package management. 

It can be installed on *nix systems with below command

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

To install gvm on Windows, can download the binary at Github. Then put the binary under your %PATH% and it can be used.

Thereafter can just use gvm install to install different versions of go. 

C:\Users\pike6\Downloads>gvm install 1.16.4

Downloading Go v1.16.4... Please wait...
Successfully installed Go version 1.16.4.
To use this version, run gvm use 1.16.4. This will also set your GOROOT.

If wanna use a specific version of go, can run

gvm use 1.16.4

With this, the go command will be specified version of go and it doesn't need to be go[version].

MULTIPLE VERSION  GO BINARY  GO VERSION 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

Can you guess the end?

When two cars are competing for the same lane, the unexpected happens.