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
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.
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.
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!
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With