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: misleading warning on GOROOT == GOPATH in module mode #47889

Open
mitar opened this issue Aug 22, 2021 · 11 comments
Open

cmd/go: misleading warning on GOROOT == GOPATH in module mode #47889

mitar opened this issue Aug 22, 2021 · 11 comments
Labels
GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mitar
Copy link
Contributor

mitar commented Aug 22, 2021

What version of Go are you using (go version)?

go version go1.17 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build561180864=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I was installing go install github.com/golang/protobuf/protoc-gen-go@v1.5.2.

Inside a fresh system I did:

$ curl -L https://golang.org/dl/go1.17.linux-amd64.tar.gz | tar -C /usr/local -xz
$ export GOPATH=/usr/local/go
$ export PATH="${GOPATH}/bin:${PATH}"
$ go install github.com/golang/protobuf/protoc-gen-go@v1.5.2
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
go: downloading github.com/golang/protobuf v1.5.2
go: downloading google.golang.org/protobuf v1.26.0
$ ls -al /usr/local/go/bin
total 25120
drwxr-xr-x  2 root root     4096 Aug 22 14:11 .
drwxr-xr-x 10 root root     4096 Aug 16 16:27 ..
-rwxr-xr-x  1 root root 14007666 Aug 16 16:30 go
-rwxr-xr-x  1 root root  3318877 Aug 16 16:30 gofmt
-rwxr-xr-x  1 root root  8384142 Aug 22 14:11 protoc-gen-go
$ ls -al /root/go/bin
ls: cannot access '/root/go/bin': No such file or directory

In another fresh system I did:

$ curl -L https://golang.org/dl/go1.17.linux-amd64.tar.gz | tar -C /usr/local -xz
$ export PATH="/usr/local/go/bin:${PATH}"
$ go install github.com/golang/protobuf/protoc-gen-go@v1.5.2
go: downloading github.com/golang/protobuf v1.5.2
go: downloading google.golang.org/protobuf v1.26.0
$ ls -al /usr/local/go/bin
total 16932
drwxr-xr-x  2 root root     4096 Aug 16 16:30 .
drwxr-xr-x 10 root root     4096 Aug 16 16:27 ..
-rwxr-xr-x  1 root root 14007666 Aug 16 16:30 go
-rwxr-xr-x  1 root root  3318877 Aug 16 16:30 gofmt
$ ls -al /root/go/bin
total 8196
drwxr-xr-x 2 root root    4096 Aug 22 14:14 .
drwxr-xr-x 4 root root    4096 Aug 22 14:14 ..
-rwxr-xr-x 1 root root 8383846 Aug 22 14:14 protoc-gen-go

What did you expect to see?

As you see, setting GOPATH is critical for getting binary installation into /usr/local/go/bin instead of /root/go/bin. Without it, it does not work. So the warning saying GOPATH set to GOROOT (/usr/local/go) has no effect is misleading. Setting GOPATH has a pretty dramatic effect.

What did you see instead?

I have seen the warning saying GOPATH set to GOROOT (/usr/local/go) has no effect and I assumed I can just remove setting GOPATH but it turns out that is not true. It has an effect.

I think this is important because installation instructions only talk about setting export PATH=$PATH:/usr/local/go/bin, but without setting GOPATH. So installed binaries go into /root/go/bin which is not in PATH based on the installation instructions.

@seankhliao
Copy link
Member

Setting GOPATH to GOROOT isn't a supported way of working as it mixes user code with the standard library. If you need to control where the binaries are installed, use GOBIN.

@mitar
Copy link
Contributor Author

mitar commented Aug 22, 2021

I think issues reported here still hold:

  • Warning is misleading.
  • Documentation sets PATH only to /usr/local/go/bin but not also sets GOBIN, making go install install into a directory not on PATH.

@seankhliao seankhliao changed the title Misleading warning: warning: GOPATH set to GOROOT (/usr/local/go) has no effect cmd/go: misleading warning on GOROOT == GOPATH in module mode Aug 22, 2021
@seankhliao
Copy link
Member

Looks like none of the commands in module mode check check this
cc @bcmills @jayconrod @matloob

@seankhliao seankhliao reopened this Aug 22, 2021
@seankhliao seankhliao added GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 22, 2021
@jayconrod jayconrod added this to the Go1.18 milestone Aug 23, 2021
@jayconrod jayconrod added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 23, 2021
@jayconrod
Copy link
Contributor

We should fix this. The install directory should not be set to $GOPATH/bin if the first element of GOPATH is the same as GOROOT.

We should also mention adding $GOPATH/bin to the install instructions. That's covered by #44930.

I'd recommend against installing anything in $GOROOT/bin that isn't usually there. If you're setting GOBIN, it's fine to point it to a directory already in PATH like /usr/local/bin.

@seankhliao
Copy link
Member

Can GOROOT == GOPATH be an error instead of just a warning?

@roulpriya
Copy link

export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/home/priyambada/golib
export PATH=$PATH:$GOPATH/bin

This eventually works for me without an error
If you installed GoLang in a custom directory other than the default (/usr/local/), you must specify that directory as the value of the GOROOT variable.

@ianlancetaylor
Copy link
Member

@bcmills This is in the 1.18 milestone; time to move to 1.19? Thanks.

@bcmills bcmills modified the milestones: Go1.18, Go1.19 Feb 1, 2022
@bcmills bcmills self-assigned this Feb 1, 2022
@danishprakash
Copy link

Is this something an external contributor can pick up? I'd like to work on this. Thanks

@mitar
Copy link
Contributor Author

mitar commented Apr 7, 2022

@danishprakash Of course.

@bcmills bcmills modified the milestones: Go1.19, Backlog Jun 1, 2022
@bcmills bcmills removed their assignment Jun 1, 2022
@Marityr
Copy link

Marityr commented Feb 12, 2023

export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=/home/priyambada/golib export PATH=$PATH:$GOPATH/bin

This eventually works for me without an error If you installed GoLang in a custom directory other than the default (/usr/local/), you must specify that directory as the value of the GOROOT variable.

Thank you. when upgrading from 1.19 to 1.20 it helped

@MatteoOreficeIT
Copy link

MatteoOreficeIT commented Sep 13, 2023

Guys you must seriously consider to produce a comprehensible, complete and well organized documentation and you want to speak also to beginner not only to internal engineering teams

I worked with many languages compiled or intepreted but I cannot believe that GO was born without a decent dependencies management tools at the early stages, it sounds like a big oversight or a language was born in 1990.

This could have happened to Java or C++ but not to GO , not in 2009

I read many discussions about GOPATH, go.mod, GOROOT, import path, and bla bla .... those will be recognized by people as battle arenas not confortable place, this could be frustrating for US to see people fighting

Documentation cannot rise to the level of using the word "ecosystem" before stopping to be a patch work ! believe me, just see their facial expressions when they read the doc

To be clear I am not speaking about the power of the GO language but about the way doc is organized and made understandable by common people like me

I am sure a beginner cannot find a simple page where GOROOT is explained with its default !!! and worse not to understand that it cannot be the same as GOPATH wasting a lot of time

The simple fact this discussion exists is POC something is not happening as you wanted !

Please. Become aware of this

I am very interested in learning go but don't make me feel like I'm swimming against the current of a river

Didn't we need a language easy to understand ?? so spend time to have a decent doc

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

9 participants