missing $GOPATH

1,358 views
Skip to first unread message

Dan Kortschak

unread,
Sep 26, 2019, 10:36:18 PM9/26/19
to golang-nuts
I am looking at some changes we have made to make code generation
independent of GOPATH since from the SettingGOPATH page of the wiki
says "If no GOPATH is set, it is assumed to be $HOME/go on Unix systems
and %USERPROFILE%\go on Windows."

However, when I run `go env` I see `missing $GOPATH` in response.

```
~ $ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/user/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
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-build038144482=/tmp/go-build -gno-record-gcc-switches"
~ $ unset GOPATH
~ $ go env
missing $GOPATH
```

Is this expected now?

Ian Lance Taylor

unread,
Sep 26, 2019, 11:19:55 PM9/26/19
to Dan Kortschak, golang-nuts
The problem you are encountering is that /home/user/go is already
being used for GOROOT, so it can't be used for GOPATH. If the default
location is unavailable, there is no fallback, so you get "missing
$GOPATH".

Ian

Dan Kortschak

unread,
Sep 26, 2019, 11:21:37 PM9/26/19
to Ian Lance Taylor, golang-nuts
Yes, that explains it. Perhaps the error could be more informative.

Dan Kortschak

unread,
Sep 27, 2019, 1:49:45 AM9/27/19
to Ian Lance Taylor, golang-nuts
Looking into it it appears that there's active work in
go/build.defaultGOPATH that makes returning an informative error
message impossible.

This made sense when it was done in 428df5e39c0[1], but since then
57568958774[2] has gone in which changes the message from something
that was useful to something that is now almost devoid of information.

was:
```
go install: no install location for directory
/home/user/src/path.org/to/package outside GOPATH
For more details see: 'go help gopath'
```

now:
```
missing $GOPATH
```

ISTM that the warning provided before 428df5e39c0 is now the better
option in terms of confusion. Perhaps that warning could be an error so
that functional behaviour that exists now would remain, but with an
actual explanation. Stopping with this error would be helpful:

```
warning: GOPATH set to GOROOT (/home/user/go) has no effect
```


[1]https://go-review.googlesource.com/c/go/+/33105/
[2]https://go-review.googlesource.com/c/go/+/118095/

Dan Kortschak

unread,
Sep 30, 2019, 11:33:41 PM9/30/19
to Ian Lance Taylor, golang-nuts
Reply all
Reply to author
Forward
0 new messages