Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple versions of go

Tags:

go

I am trying to learn go-lng following the official docs here: https://golang.org/doc/install

I am stuck on the step installing extra go versions. Apparently this line should install a different version of go and make the executable available in my $PATH but it's not happening:

go get golang.org/dl/go1.10.7

Instead what I see is:

c.craig$ go get golang.org/dl/go1.10.7
c.craig$ go1.10.7 download
-bash: go1.10.7: command not found

Where am I going wrong? I've tried it with a space assuming this was just a typo in the docs but even that doesn't work:

c.craig$ go get golang.org/dl/go1.10.7
c.craig$ go 1.10.7 download
go 1.10.7: unknown command
like image 888
Cliff Avatar asked Apr 17 '20 20:04

Cliff


People also ask

How do I install multiple versions of go on Windows?

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. 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.

Is it possible to run multiple versions of go in RVM?

For example, there can be multiple JDKs, multiple versions of Ruby using RVM. For GoLang, there is a similar tool called GVM which can also be used to maintain multiple versions of Go in one single environment.

Should you run multiple versions of Go programming language in one project?

As a user of the Go programming language, I’ve found it useful to enable the running multiple versions within a single project. If this is something you’ve tried or have considered, great!

How do I run multiple versions of Golang in the same environment?

This is simple for getting started, but also can be limiting. A more flexible set up is to enable running multiple versions within the same environment via go1.15 or go1.16 commands, for example. An alternative approach involves setting your terminal’s PATH environment variable to point to a specific Go version’s SDK.


2 Answers

The binary is installed $HOME/go/bin (or more accurately the bin directory under the path you get from go env GOPATH). The go get command doesn't update your $PATH, so you need to add the install directory to your $PATH yourself.

like image 185
Paul Hankin Avatar answered Oct 17 '22 13:10

Paul Hankin


After setting the following path variables in .bash_profile (do not forget to run: source ~/.bash_profile)

$ export GOPATH=$HOME/go
$ export GOBIN=$HOME/go/bin

Install go version in one terminal:

$ go get golang.org/dl/go1.13.15
$ go1.13.15 download

Now you also want to install another go version say go1.15.13 by executing the below commands (remember to set the path as told above)

$ go get golang.org/dl/go1.15.13
$ go1.15.13 download

Now you have two go versions installed; 1.13.15 and 1.15.13.

Say, in one terminal, you want to use version 1.13.15 so you can create an alias as below in that terminal window:

$ alias go="go1.13.15"
$ go version
go version go1.13.15 darwin/amd64

In another terminal you can switch to different version

$ alias go="go1.15.13"
$ go version
go version go1.15.13 darwin/amd64
like image 20
rgoel Avatar answered Oct 17 '22 14:10

rgoel