温馨提示×

debian golang代理怎么设

小樊
36
2026-09-17 10:22:43
栏目: 编程语言

在 Debian 上设置 Golang 代理(通常指 Go 模块代理 GOPROXY),常见做法如下:


一、临时设置(当前终端生效)

export GOPROXY=https://proxy.golang.org,direct

国内推荐:

export GOPROXY=https://goproxy.cn,direct

export GOPROXY=https://goproxy.io,direct

二、永久设置(用户级别)

编辑 ~/.bashrc~/.profile

nano ~/.bashrc

添加:

export GOPROXY=https://goproxy.cn,direct
export GOSUMDB=off   # 可选,关闭校验(不推荐生产)

生效:

source ~/.bashrc

三、系统级设置(所有用户)

sudo nano /etc/profile.d/go.sh

写入:

export GOPROXY=https://goproxy.cn,direct

保存后重启或:

source /etc/profile

四、使用 go env 设置(推荐)

go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOSUMDB=off   # 可选

查看:

go env GOPROXY

五、配合 HTTP/HTTPS 代理(如公司网络)

export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890

六、验证

go get github.com/gin-gonic/gin

常用国内代理

  • https://goproxy.cn
  • https://goproxy.io
  • https://mirrors.aliyun.com/goproxy/

如果你是指 apt 代理git 代理,也可以告诉我。

0