我go env
用来检查 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"
有节目GOPATH="/usr/local/Cellar/go/1.7.6"
但在我/usr/local/Cellar/go
那里只有一个1.8.1/
,为什么不匹配?这是否是因为更新?如何制作go env
合适的?
EDIT-01
我通过以下方式在我的 Mac 中安装了新的 go:
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
但是现在当我检查时go env
,仍然有错误的路径:
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
当我使用这种方式检查 go env 时,会收到警告。
$ 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