问题
在使用homebrew安装golang 1.14时,执行go build会报请求超时错误
brew install go@1.14
...
==> go build
Last 15 lines from /Users/xx/Library/Logs/Homebrew/go@1.14/03.go:
2021-08-18 01:14:01 +0800
go
build
go: golang.org/x/net@v0.0.0-20190620200207-3b0461eec859: Get "https://proxy.golang.org/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.mod": dial tcp 142.251.43.17:443: i/o timeout
问题定位
初步断定是在执行’go build’环节出现代理问题。国内用户需要设置代理
配置goproxy
尝试设置以上环境变量
export GOPROXY=https://goproxy.io,direct
export GO111MODULE=on
但不幸的是仍报相同错误,怀疑是安装过程中某个环节unset了环境变量
查看更多安装信息
使用-v参数进行安装
brew install go@1.14 -v
查看到homebrew安装golang 1.14的ruby脚本路径: ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/go@1.14.rb’
并且能看到安装过程会下载2个压缩包,然后执行’./make.bash –no-clean’
/usr/bin/sandbox-exec -f /private/tmp/homebrew20210818-15926-10cv6ja.sb nice ruby -W1 -- /usr/local/Homebrew/Library/Homebrew/build.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/go@1.14.rb --verbose
...
tar --extract --no-same-owner --file /Users/huangcheng/Library/Caches/Homebrew/downloads/5ce0f7e2a4821a377e09f2355ce146bf66f8e11bb6fc93320c8146a05198abc6--go1.14.15.src.tar.gz --directory /private/tmp/d20210818-15927-184e6dj
...
tar --extract --no-same-owner --file /Users/huangcheng/Library/Caches/Homebrew/downloads/ad0901a23a51bac69b65f20bbc8e3fe998bc87a3be91d0859ef27bd1fe537709--go1.7.darwin-amd64.tar.gz --directory /private/tmp/d20210818-15927-1qdv80h
...
==> ./make.bash --no-clean
...
打开rb文件,里面找到’make.bash’相关代码,是在src目录下执行make.bash
cd "src" do
ENV["GOROOT_FINAL"] = libexec
system "./make.bash", "--no-clean"
找到这两个压缩包,解压找到src目录下的make.bash文件。发现之前设置的环境变量果然被unset了-_-!
export GOENV=off
unset GOBIN # Issue 14340
unset GOFLAGS
unset GO111MODULE
如何设置GO111MODULE
打开’/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/go@1.14.rb’文件,找到go build调用代码
...
system "go", "build"
...
在执行代码前,重新设置一下环节变量
...
ENV['GOPROXY'] = 'https://goproxy.io,direct'
ENV['GO111MODULE'] = 'on'
system "go", "build"
...
保存,重新执行安装命令’brew install go@1.14 -v’
==> Summary
🍺 /usr/local/Cellar/go@1.14/1.14.15: 9,471 files, 425.7MB, built in 1 minute 16 seconds
成功!
今天的文章Homebrew安装golang报dial tcp 142.251.43.17:443: i/o timeout 代理错误分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/17614.html