在 Debian 上设置 Golang 代理(主要是 Go Module 代理),通常有几种方式,最常用的是配置 GOPROXY。
go env -w GOPROXY=https://proxy.golang.org,https://goproxy.cn,direct
或只用国内镜像:
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPROXY=https://proxy.golang.org,direct
export GOPROXY=https://goproxy.cn,direct
export GOSUMDB=off # 可选,关闭校验(不推荐生产环境)
查看当前配置:
go env GOPROXY
git / go get 设置网络代理(HTTP/HTTPS)如果你的服务器需要走 HTTP 代理访问外网:
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
或写入 ~/.bashrc:
echo 'export http_proxy=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export https_proxy=http://127.0.0.1:7890' >> ~/.bashrc
source ~/.bashrc
go env -w GOPRIVATE=git.example.com,github.com/org/private
这样 Go 不会通过代理下载私有库。
go env
go env -u GOPROXY
如果你是在 Docker / CI / 内网环境,或者 无法访问外网,可以告诉我具体场景,我可以给你更合适的方案。