在 Debian 上配置 Golang 的代理(通常指 Go Module 代理,如 GOPROXY),可以按下面步骤操作。
export GOPROXY=https://proxy.golang.org,direct
国内常用代理:
export GOPROXY=https://goproxy.cn,direct
# 或
export GOPROXY=https://goproxy.io,direct
~/.bashrc 或 ~/.profileecho 'export GOPROXY=https://goproxy.cn,direct' >> ~/.bashrc
source ~/.bashrc
如果是 zsh:
echo 'export GOPROXY=https://goproxy.cn,direct' >> ~/.zshrc
source ~/.zshrc
go env -w GOPROXY=https://goproxy.cn,direct
查看是否生效:
go env GOPROXY
go env -w GOPROXY=https://proxy.golang.org,direct
或删除环境变量:
go env -u GOPROXY
如果公司有私有 Git 仓库:
go env -w GOPRIVATE=git.example.com,github.com/org/private
这样这些域名不会走代理。
Go 1.13+ 默认开启,老版本可手动开:
go env -w GO111MODULE=on
go env
或测试拉包:
go get github.com/gin-gonic/gin
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPRIVATE=git.company.com
如果你是指 HTTP 网络代理(如公司内网) 或 Docker 里配置 Go 代理,也可以告诉我具体场景。