1

I use go env to check the GOPATH:

$ go env
GOARCH="amd64"
GOBIN="/usr/local/Cellar/go/1.7.6/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/Cellar/go/1.7.6"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qp/h96_smbd55ggtzwvml8wpl9h0000gn/T/go-build644796325=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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"

there shows GOPATH="/usr/local/Cellar/go/1.7.6"

but under my /usr/local/Cellar/go there only have 1.8.1/, why it not match ? whether this is because of update? how to make the go env suitably?


EDIT-01

I installed the new go in my Mac by:

tar -C /usr/local -xzf go1.14.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
$ go version
go version go1.14.4 darwin/amd64

But now when I check the go env, there still is the wrong path:

dele-MBP:go ldl$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/usr/local/Cellar/go/1.7.6/bin"
GOCACHE="/Users/dele/Library/Caches/go-build"
GOENV="/Users/dele/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/usr/local/Cellar/go/1.7.6"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qp/h96_smbd55ggtzwvml8wpl9h0000gn/T/go-build431355334=/tmp/go-build -gno-record-gcc-switches -fno-common"

EDIT-02

When I use this way to check the go env, there get warning.

$ go env -w GOPATH="/usr/local/go"
warning: go env -w GOPATH=... does not override conflicting OS environment variable

EDIT-03

$ cat "${HOME}/Library/Application Support/go/env"
GOPATH=/usr/local/go

EDIT-04

dele-MBP:go ldl$ unset GOPATH
dele-MBP:go ldl$ go env -w GOPATH="/usr/local/go"
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
user7693832
  • 6,119
  • 19
  • 63
  • 114
  • GOPATH is typically set to a directory under $HOME. Is GOPATH set in .bashrc or one of your other initialization scripts? Also, the Go official installer usually results in a better experience than brew. – Charlie Tumahai Jun 24 '20 at 02:35
  • Run `grep GOPATH $HOME/.*` and report any lines found. Also, set GOPATH to a directory in $HOME or don't set it at all for the default $HOME/go. – Charlie Tumahai Jun 24 '20 at 03:34
  • 1
    Start by deinstalling the homebrew version of Go. – Volker Jun 24 '20 at 05:49

1 Answers1

1

go env settings - depending on your OS - are persisted in your user account's home directory. For example, on MacOS you'll find it here:

cat "${HOME}/Library/Application Support/go/env"

GOPROXY=direct

It's most likely you have an old setting from a previous brew install perhaps with an older version.

To correct simply write the correct value, like so:

go env -w GOPATH="/usr/local/Cellar/go/1.8.1"
colm.anseo
  • 19,337
  • 4
  • 43
  • 52
  • @244boy as @MuffinTop alluded mentioned, if `GOPATH` ENV VAR is exported - you will get that "does not override" warning with `go env -w`. `unset GOPATH` and retry. – colm.anseo Jun 24 '20 at 03:32
  • 1
    And as @MuffinTop suggested, `GOPATH` is being set in some user profile - so find that initial setting - otherwise this problem will reappear when you create a new shell. – colm.anseo Jun 24 '20 at 03:33