Homebrew升级Go版本后出现的问题

原版本1.18.1,昨天意外使用homebrew 为所有包执行了 upgrade 导致vscode写的项目无法跑起来。环境配置都正确,求答疑这问题应如何解决~

错误提示是(部分):

tom:Boom/ $ go run main.go                                                              [15:52:48]
../../pkg/mod/github.com/gin-gonic/gin@v1.8.2/response_writer.go:8:2: package bufio is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/bufio)
../../pkg/mod/github.com/gin-gonic/gin@v1.8.2/recovery.go:8:2: package bytes is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/bytes)
../../pkg/mod/golang.org/x/net@v0.4.0/http2/transport.go:12:2: package compress/gzip is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/compress/gzip)
../../pkg/mod/golang.org/x/text@v0.5.0/unicode/bidi/bracket.go:8:2: package container/list is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/container/list)
../../pkg/mod/github.com/go-playground/validator/v10@v10.11.1/baked_in.go:5:2: package context is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/context)
../../pkg/mod/golang.org/x/crypto@v0.0.0-20211215153901-e495a2d5b3d3/sha3/register.go:11:2: package crypto is not in GOROOT (/usr/local/Cellar/go/1.19.4/src/crypto)

Go env :

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tom/Library/Caches/go-build"
GOENV="/Users/tom/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tom/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tom/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/Cellar/go/1.19.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.19.4/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/tom/go/src/Boom/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s_/3jcs33rs0td_q34h_cc6qmtr0000gn/T/go-build3146486164=/tmp/go-build -gno-record-gcc-switches -fno-common"

Go安装路径:

tom:Boom/ $ which go                                                                                                                         [16:00:14]
/usr/local/Cellar/go/1.19.4/bin/go
最佳答案

GOROOT 设置为 /usr/local/Cellar/go/1.19.4/libexec 就可以了!

go env -w GOROOT=/usr/local/Cellar/go/1.19.4/libexec

在 Goland 中,如果因为升级而导致找不到 GOROOT 时,IDE 会提示设置新的版本目录。

否则就需要自己手动设置!

2周前 评论
讨论数量: 3

删除 go 文件,重新安装试试

3周前 评论

转用 gvm 吧,还可以随时切换版本

2周前 评论

GOROOT 设置为 /usr/local/Cellar/go/1.19.4/libexec 就可以了!

go env -w GOROOT=/usr/local/Cellar/go/1.19.4/libexec

在 Goland 中,如果因为升级而导致找不到 GOROOT 时,IDE 会提示设置新的版本目录。

否则就需要自己手动设置!

2周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!