在Ubuntu上配置Golang代理主要有以下两种常用方式:
export http_proxy="http://your.proxy.server:port"
export https_proxy="http://your.proxy.server:port"
(若需认证,格式为http://username:password@proxy_server:port
)
将上述命令添加到~/.bashrc
或~/.zshrc
文件中,然后执行:
source ~/.bashrc # 或 source ~/.zshrc
go env -w GO111MODULE=on # 启用模块支持(Go 1.13+默认开启)
go env -w GOPROXY=https://goproxy.cn,direct # 推荐使用国内镜像(如七牛云或官方代理)
direct
表示代理不可用时直接连接源服务器。go env | grep -E "HTTP_PROXY|HTTPS_PROXY|GOPROXY"
输出应显示设置的代理地址。
git config
命令。