Reputation: 11248
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
Upvotes: 30
Views: 56618
Reputation: 25199
You may wish to try Go Version Manager (gvm
):
curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer | bash
gvm listall
gvm install go1.10.7 [-B]
gvm use go1.10.7 [--default]
gvm list
In case you want to compile from source and don't have go
installed:
gvm install go1.4 -B
gvm use go1.4
#CGO_ENABLED=0
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.10.7
gvm use go1.10.7
In case you're getting compiling errors, you may wish to uncomment CGO_ENABLED=0
prior to compiling from the source.
And you can always see what's available:
gvm list
or rely on gvm
gvm install latest
Upvotes: 20
Reputation: 35414
In Ubuntu, the packages are surprisingly fresh:
$ sudo apt install golang-1.23-go
$ sudo update-alternatives --install /usr/bin/go go /usr/lib/go-1.23/bin/go 20
Upvotes: 0
Reputation: 540
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 install golang.org/dl/go1.13.15@latest
$ 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 install golang.org/dl/go1.15.13@latest
$ 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
Upvotes: 44
Reputation: 1
what about goup-rs, it wirte in rust, single binary but only depend git
.
$ goup install
[2024-01-30T00:38:48Z INFO ] Installing go1.21.6 ...
[2024-01-30T00:38:48Z INFO ] Unpacking /home/thinkgo/.goup/go1.21.6/go1.21.6.linux-amd64.tar.gz ...
[2024-01-30T00:38:48Z INFO ] go1.21.6 installed in /home/thinkgo/.goup/go1.21.6
[2024-01-30T00:38:48Z INFO ] Default Go is set to 'go1.21.6'
$ goup list
| VERSION | ACTIVE |
|---------|--------|
| 1.21.6 | * |
$ go env GOROOT
/home/thinkgo/.goup/current
$ go version
go version go1.21.6 linux/amd64
$ GOUP_GO_HOST=https://golang.google.cn goup install 1.21.6
Upvotes: 0
Reputation: 129
I faced the same issue when trying to install version 1.17.11, my base version is 1.18.2.
Followed instructions from here https://go.dev/doc/manage-install but it didn't work for me.
Then, i realized, after ran go install golang.org/dl/go<version>@latest
(where <version>
is the version you need), a binary file name go<version>
will be downloaded in $HOME/go/bin/
.
Move to $HOME/go/bin/
, run ./go<version> download
, and version you need will be downloaded at $HOME/sdk/
To use the version you had just downloaded, add this line to the end of ~/.bashrc
file:
alias go<version>=$HOME/sdk/go<version>/bin/go
Save and exit. Run source ~/.bashrc
to execute it!
Upvotes: 10
Reputation: 4877
I know I am quite late to the party, but being really fed up with how multiple versions should be managed in Go, I decided to build a simple CLI that does the trick easily.
https://github.com/VassilisPallas/gvs/
I released it a couple of days ago, which means there are a few things that need to be added as features. But feel free to reach out to me if you see any required improvements/new features.
Upvotes: 0
Reputation: 935
I recommend https://github.com/stefanmaric/g as an alternative of gvm
in the field of go version manager.
Upvotes: 0
Reputation: 31
Referring to the link: https://go.dev/doc/manage-install
, step by step.
And if come up with this error:
$ c.craig$ go get golang.org/dl/go1.10.7
$ c.craig$ go1.10.7 download
-bash: go1.10.7: command not found
try to add these codes to your shell profile(like.zshrc
):
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$(go env GOPATH)/bin
the first path is where your base go installed, mostly is /usr/local/go/bin
.
And then the error would be fixed.
Upvotes: 3
Reputation: 1
I got the same problem as yours, after I knew that go is back-compatible, I copy the /usr/local/go/bin/go to /usr/local/go/bin/go{version}.
Upvotes: 0
Reputation: 528
I also found useful using this tool to switch between versions: Freshgo - https://nikfot.github.io/freshgo/ It is a go binary and easy to install (linux).
I installs go versions from the source easily and can keep a backup of your go source files so if you switch between versions you save some little time from go pkg downloads.
Easy as that:
freshgo select -v 1.19
I also installed it in my shell to check for latest versions, with a ready script:
echo "${PATH to freshgo repo}/check_ver.sh" >> ~/.profile
Upvotes: 0
Reputation: 125
For Mac users it's easier and I guess for Linux users should be similar, you just need to:
go version
go1.13.15
you can run the following command(I think the @latest is optional): go install golang.org/dl/go1.13.15@latest
, if nothing happens then everything is ok.go1.13.15 download
export GOROOT=$HOME/sdk/go1.13.15
go version
you should seego version go1.13.15 darwin/amd64
Upvotes: -4
Reputation: 58271
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.
Upvotes: 18