go: cmd/go: using go get to install new versions of go doesn't seem to work

From this docs page,

https://golang.org/doc/install#extra_versions

It may be useful to have multiple Go versions installed on the same machine, for example, to ensure that a package’s tests pass on multiple Go versions. Once you have one Go version installed, you can install another (such as 1.10.7) as follows:

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

Note: I ran all of these commands as root, this shouldn’t be a permissions issue.

I attempted to install go1.12.17 via go 1.10.1, using the guide in the wiki.

I attempted to run go get golang.org/dl/go1.12.17, it completed without any message (error or otherwise), however it didn’t seem to do anything.

  • Attempting go1.12.17 download gives me bash: go1.12.17: command not found.
  • which go1.12.17 comes back with no results
  • There appears to be nothing new in /usr/bin/, /usr/local/bin/, and no files have been downloaded to the directory I’m in
  • go version shows that it’s still running go version go1.10.1 linux/386

On a whim I tried installing something older thinking maybe this command only works for downgrading go, but attempting to install go1.9.1 gave me the same result.

If it matters, go1.10.1 is from apt, I’m running Ubuntu 18.04; the go get method for installing multiple go versions sounds handy but I’m OK with uninstalling the official go version from Canonical and getting a different version from a PPA, that was my fix for this previously.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="386"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="387"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build682500140=/tmp/go-build -gno-record-gcc-switches"

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I had the same problem.

if you had $GOPATH/bin in $PATH (as is recommended)

Where it is recommended? Not in getting started doc. If you follow just instructions there, on Linux, you do:

  • Run tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
  • Add export PATH=$PATH:/usr/local/go/bin to .profile, which makes go work great.
  • Then you do go get golang.org/dl/go1.10.7, something happens.
  • You try go1.10.7 download and it fails because it is not found in PATH.

I think that document should mention that you should set GOPATH and/or set $GOPATH/bin to PATH as well.

go get downloads to $GOPATH/bin as usual, if you had $GOPATH/bin in $PATH (as is recommended) and ran it as a normal user it would have worked (for your user, go get is not a replacement for global installs)

It looks like the go get command downloaded the file to /root/go/bin, and that folder wasn’t added to path.

It might be worth making the download destination path clearer in the docs, or maybe having the go get command say where the binary was saved. The go download command worked properly after I was able to find the go1.12.17 executable. It’s a bit confusing because which go goes to /usr/bin/go, not /home/root/go.

In any case I don’t think this method is viable for what I’m trying to do after playing around with it a bit, I’m going to use the PPA route instead.

Instructions were updated by https://go-review.googlesource.com/c/go/+/254365 The current page of reference to handle multiple versions of go is https://go.dev/doc/manage-install which explains how to use go install to download another version using the installed package.

It seems that issue can be closed.

The instruction in GO’s document is unclear. After run go install golang.org/dl/go<version>@latest, a binary file will be downloaded in $HOME/go/bin/ Move to that directory, then run ./go<version> download. And the version you need will be downloaded at $HOME/sdk/ To use that version, you need to add the following line to ~/.bashrc alias go<version>=$HOME/sdk/go<version>/bin/go After saving & exit, you need to run source ~/.bashrc and in some cases, you should restart the terminal. I don’t know why the document doesn’t specify this, but I had the same problem as the OP and after observing, I realized how to fix it.

If you add the binary location to the documentation or add a comment saying that go install will install the new version in the ~/go/bin that would help new users.

No, the binary file will be downloaded in ~/go/bin, run that binary file with ./go<version> download and the version you need will be installed in $HOME/sdk/. To use that version, you need to add the following line to ~/.bashrc alias go<version>=$HOME/sdk/go<version>/bin/go After saving & exit, you need to run source ~/.bashrc and in some cases, you should restart the terminal. I don’t know why the document doesn’t specify this, but I had the same problem as the OP and after observing, I realized how to fix it.

Can you give more detail about your problem? You can’t find go binary file or don’t know how to add the version you need to path?

@dongocanh96 I read this in the doc:

To install additional Go versions, run the `go install command`, specifying the download location of the version you want to install. The following example illustrates with version 1.10.7:

$ go install golang.org/dl/go1.10.7@latest
$ go1.10.7 download

I totally missed the go install command link which explain things in details. So being new to go I didn’t know my installs were going in ~/go/bin/.

go1.10.7 download only works if the ~/go/bin/ folder is in your $PATH.

If you add the binary location to the documentation or add a comment saying that go install will install the new version in the ~/go/bin that would help new users.

This is still unclear.

I’m just following the doc here: https://go.dev/doc/manage-install#linux-mac-bsd And it’s not mentioned anywhere that my new go binary file will be in ~/go/bin/ … or add this path to $PATH at install time?

Bad first experience and 15 min lost because of it. Please fix this for future users.

@superlazyname It probably should give a better message, yes. #35912 is the tracking issue for that.