在CentOS上配置Go语言代理,可以按照以下步骤进行:
设置GOPROXY环境变量
打开终端,编辑你的shell配置文件(如.bashrc
或.zshrc
),添加以下行:
export GOPROXY=https://goproxy.cn,direct
这里使用了https://goproxy.cn
作为代理服务器,direct
表示如果代理不可用则直接连接。
保存文件并运行以下命令使更改生效:
source ~/.bashrc # 或者 source ~/.zshrc
验证配置
运行以下命令来验证代理是否生效:
go env | grep GOPROXY
你应该能看到类似以下的输出:
GOPROXY="https://goproxy.cn,direct"
go env
命令临时设置如果你不想修改shell配置文件,也可以直接在终端中临时设置代理:
go env -w GOPROXY=https://goproxy.cn,direct
如果你有多个代理服务器,可以用逗号分隔它们:
export GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
go get
命令时指定代理如果你只想在使用go get
命令时使用代理,可以在命令行中直接指定:
GOPROXY=https://goproxy.cn go get github.com/example/package
go mod tidy
等,因此请谨慎配置。通过以上步骤,你应该能够在CentOS上成功配置Go语言代理。