温馨提示×

debian golang代理如何设

小樊
40
2026-09-11 05:17:40
栏目: 编程语言

在 Debian 上设置 Golang 代理(主要是 Go Module 代理),通常有几种方式,最常用的是配置 GOPROXY


一、设置 Go Module 代理(推荐)

1️⃣ 使用官方代理 + 国内镜像(推荐国内用户)

go env -w GOPROXY=https://proxy.golang.org,https://goproxy.cn,direct

或只用国内镜像:

go env -w GOPROXY=https://goproxy.cn,direct

2️⃣ 只使用官方代理

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 环境变量

go env

✅ 清除代理设置

go env -u GOPROXY

如果你是在 Docker / CI / 内网环境,或者 无法访问外网,可以告诉我具体场景,我可以给你更合适的方案。

0