gvm install 问题记录

1,539 阅读3分钟

背景

今天突然发现我本地使用的 golang 版本太低了(go1.16.15),最新的版本已经到 go1.23.0 了,因此想用 golang 的多版本管理工具 gvm 来更新一下我的 golang 版本,但是遇到了一系列的问题,下面是我的问题记录。

gvm install go1.22.6 报错:

% gvm install go1.22.6 
Updating Go source...
ERROR: Couldn't get latest Go version info. Check the logs /Users/xxx/.gvm/logs/go-download.log
ERROR: Unrecognized Go version

查看 log 文件:

% tail go-download.log
Cloning into '/Users/xxx/.gvm/archive/go'...
fatal: unable to access 'https://github.com/golang/go/': LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
Cloning into '/Users/xxx/.gvm/archive/go'...
Updating files: 100% (12216/12216), done.
fatal: unable to access 'https://github.com/golang/go/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/golang/go/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/golang/go/': Empty reply from server
fatal: unable to access 'https://github.com/golang/go/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
fatal: unable to access 'https://github.com/golang/go/': Failed to connect to github.com port 443 after 75005 ms: Operation timed out

看起来是网络的问题,接下来我就各种搜资料。

资料一:fatal: unable to access 'github.com/golang/go/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

该错误是因为 git 默认使用 http/2.0 协议,而 github 还是 http/1.1。然后我就按照指引,修改了 git 的 http 版本:

git config --global http.version HTTP/1.1

但是不管用。

资料二:修改 hosts 文件

根据报错信息:Failed to connect to github.com port 443 after 75005 ms: Operation timed out,我继续查找资料。

按照资料指引修改 hosts 文件中的 github.com 的 IP 映射。

修改了,还是不管用。

资料三:代理问题(网络问题解决了)

因为我开了代理,而我浏览器是可以访问 golang 的 github 地址的,然后我根据资料三的指引修改 git 的代理配置:

git config --global http.proxy 127.0.0.1:7890
git config --global https.proxy 127.0.0.1:7890

网络问题解决了。

网络的问题解决了,但是 gvm install 还是报错

此时的内心OS:啊啊啊啊啊啊

% gvm install go1.22.6
Updating Go source...
Installing go1.22.6...
 * Compiling...
ERROR: Failed to compile. Check the logs at /Users/xxx/.gvm/logs/go-go1.22.6-compile.log
ERROR: Failed to use installed version

查看 log 文件:

% tail go-go1.22.6-compile.log
Building Go cmd/dist using /usr/local/go. (go1.16.15 darwin/arm64)
//go:build comment without // +build comment

可以看到它其实已经把 go1.22.6 的源码下载下来了,但是 compile 失败了。

我尝试继续下载其他低版本的 golang 包 go1.18.10 是成功的。

这时我怀疑是不是我 gvm 的 golang 版本更新跨度太大而导致的问题,于是我把 go1.18.10 设置成当前的 golang 版本,然后继续下载 go1.22.6 版本:

% gvm use go1.18.10
Now using version go1.18.10


 % gvm install go1.22.6
Installing go1.22.6...
 * Compiling...
ERROR: Failed to compile. Check the logs at /Users/xxx/.gvm/logs/go-go1.22.6-compile.log
ERROR: Failed to use installed version

发现还是报编译问题,查看 log 文件:

 % tail go-go1.22.6-compile.log
Building Go cmd/dist using /Users/xxx/.gvm/gos/go1.18.10. (go1.18.10 darwin/arm64)
found packages main (build.go) and building_Go_requires_Go_1_20_6_or_later (notgo120.go) in /Users/xxx/.gvm/gos/go1.22.6/src/cmd/dist

这里打印的日志描述就更清楚了,它说:使用 go1.18.10 构建时发现包 building_Go_requires_Go_1_20_6_or_later (notgo120.go),我大概从字面意思猜它可能是想告诉我要用 go1.20.6 或更新的版本去构建 go1.22.6 相关的文件。

然后我下载 go1.20.6 版本后,切换版本,再下载 go1.22.6 就解决了,完成了这次的本地 golang 版本更新:

gvm install go1.20.6
gvm use go1.20.6
gvm install go1.22.6
gvm use go1.22.6

over, over, 完美撒花。