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: should not depend on the existence of the default $GOROOT #19187

Closed
ghost opened this issue Feb 19, 2017 · 6 comments
Closed

cmd/go: should not depend on the existence of the default $GOROOT #19187

ghost opened this issue Feb 19, 2017 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2017

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

1.8

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

linux/amd64

What did you do?

I downloaded go1.8.linux-amd64.tar.gz and extracted it into the home directory and did export PATH="/home/user/go/bin:$PATH". Then I tried to run go version.

What did you expect to see?

Go version number.

What did you see instead?

go: cannot find GOROOT directory: /usr/local/go

None of the commands build, fmt, generate, get, install, list, run, test, vet etc. do work. They all print the same error.

When I create an empty /usr/local/go, they all by some magic start to work.

@ALTree
Copy link
Member

ALTree commented Feb 19, 2017

Did you manually set GOROOT?

@ghost
Copy link
Author

ghost commented Feb 19, 2017

I didn't. The problem occurs without explicitly set GOROOT environment variable. And if I set it to /home/user/go (the location where I've unpacked the archive), things also work (unsurprisingly).

@ALTree
Copy link
Member

ALTree commented Feb 19, 2017

Please post the output of go env. Also what does echo $GOROOT print?

@ghost
Copy link
Author

ghost commented Feb 19, 2017

Please post the output of go env.

With unexported GOROOT:

$ export -n GOROOT
$ go env
go: cannot find GOROOT directory: /usr/local/go

With GOROOT set to /home/opennota/go:

$ export GOROOT=/home/opennota/go
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/home/opennota/go"
GOTOOLDIR="/home/opennota/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build941069124=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

Also what does echo $GOROOT print?

Nothing, if GOROOT is not set. /home/opennota/go, it if is.

@ALTree
Copy link
Member

ALTree commented Feb 19, 2017

I'm not sure there's anything do to here.

The GOROOT default value is baked in the executable, so if you download the precompiled binaries you'll always have /usr/local/go baked in. If you put go in another directory, you must set GOROOT (otherwise nothing will work). This is documented:

$GOROOT [..] Its value is built into the tree when it is compiled

and:

It is possible to install the Go tools to a different location. In this case you must set the GOROOT environment variable to point to the directory in which it was installed.

If you don't want /usr/local/go to be baked in the executable, you'll have to compile from source.

@ianlancetaylor
Copy link
Contributor

Closing as dup of #17833.

@golang golang locked and limited conversation to collaborators Feb 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants