Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
superlazyname opened this issue Feb 24, 2020 · 12 comments
Closed

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

superlazyname opened this issue Feb 24, 2020 · 12 comments
Labels
Documentation NeedsFix
Milestone

Comments

@superlazyname
Copy link

@superlazyname superlazyname commented Feb 24, 2020

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"

@superlazyname
Copy link
Author

@superlazyname superlazyname commented Feb 24, 2020

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.

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Feb 24, 2020

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)

@superlazyname
Copy link
Author

@superlazyname superlazyname commented Feb 24, 2020

Understood, thanks.

  • Is it normal to have go in both /usr/bin/go and ~/go or is that an apt package quirk?
  • Do typical installs only have go in ~/go? It seems like that's an easier route.

@cagedmantis cagedmantis changed the title using go get to intall new versions of go doesn't seem to work cmd/go: using go get to install new versions of go doesn't seem to work Feb 28, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Feb 28, 2020
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Feb 28, 2020

Hi @superlazyname. This seems like it's working as expected. Please comment if you disagree. I will be closing the issue.

@mitar
Copy link

@mitar mitar commented Jun 11, 2020

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.

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Jun 11, 2020

@mitar Setting the directory where go get and go install write binaries is covered in How to write Go code. But that page is meant to be read after the install instructions, so it should probably be mentioned there as well.

I'll reopen this issue and take a look soon.

@jayconrod jayconrod reopened this Jun 11, 2020
@jayconrod jayconrod self-assigned this Jun 11, 2020
@jayconrod jayconrod added Documentation NeedsFix labels Jun 11, 2020
@mitar
Copy link

@mitar mitar commented Jun 11, 2020

Thanks. Yes, I have heard about GOPATH, but then when I was reading documentation it was not mentioned. So I assumed that with new support for modules it is not necessary anymore.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 11, 2020

Change https://golang.org/cl/237584 mentions this issue: doc: update install instructions to add GOBIN to PATH

@superlazyname
Copy link
Author

@superlazyname superlazyname commented Jun 26, 2020

@cagedmantis is it possible for go to give a useful error message or something in this case? It doesn't seem like a great idea for it to just fail silently unless there's no other option.

@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Jun 26, 2020

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

@jayconrod jayconrod removed their assignment Oct 14, 2021
@iwdgo
Copy link
Contributor

@iwdgo iwdgo commented Apr 3, 2022

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.

@dongocanh96
Copy link

@dongocanh96 dongocanh96 commented Jun 13, 2022

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 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 installed at $HOME/sdk/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix
Projects
None yet
Development

No branches or pull requests

8 participants