在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
命令。