0

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
4

1 回答 1

0

go env设置 - 取决于您的操作系统 - 保存在您的用户帐户的主目录中。例如,MacOS你会在这里找到它:

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

GOPROXY=direct

您很可能拥有以前的旧设置,brew install也可能是旧版本。

要更正,只需编写正确的值,如下所示:

go env -w GOPATH="/usr/local/Cellar/go/1.8.1"
于 2020-06-24T03:18:15.267 回答