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 · 18 comments
Closed
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@superlazyname
Copy link

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

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

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

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

@mitar
Copy link
Contributor

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

@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 The path to resolution is known, but the work has not been done. labels Jun 11, 2020
@mitar
Copy link
Contributor

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

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

@superlazyname
Copy link
Author

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

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

@vagudza
Copy link

vagudza commented Aug 11, 2022

[SOLVED] for me:
go1.10.7 download - now works! As said gopherbot (#37428 (comment)) you need to add path for bin folder (where you have go binaries):
PATH=$PATH:$HOME/go/bin

@koxon
Copy link

koxon commented Nov 30, 2022

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.

@dongocanh96
Copy link

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.

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?

@koxon
Copy link

koxon commented Dec 3, 2022

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.

@dongocanh96
Copy link

dongocanh96 commented Dec 4, 2022

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.

@bdave-apptio
Copy link

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.

This worked. Thanks a lot.

@golang golang locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests