在 CentOS 上配置 Go 语言代理,可以通过设置环境变量 GOPROXY
来实现。以下是详细步骤:
首先,打开你的 CentOS 终端。
你可以临时设置 GOPROXY
环境变量,或者永久设置它。以下是两种方法:
在终端中输入以下命令来临时设置 GOPROXY
:
export GOPROXY=https://goproxy.cn,direct
这个命令将 Go 模块的代理设置为 https://goproxy.cn
,如果该代理不可用,则直接从源获取。
要永久设置 GOPROXY
,你需要将其添加到你的 shell 配置文件中。常用的 shell 配置文件有 ~/.bashrc
或 ~/.bash_profile
。
打开你的 shell 配置文件:
nano ~/.bashrc
在文件的末尾添加以下行:
export GOPROXY=https://goproxy.cn,direct
保存并关闭文件。
使更改生效:
source ~/.bashrc
你可以通过以下命令来验证 GOPROXY
是否设置成功:
echo $GOPROXY
如果输出是 https://goproxy.cn,direct
,则说明设置成功。
除了 https://goproxy.cn
,你还可以使用其他常用的 Go 模块代理,例如:
https://proxy.golang.org,direct
https://goproxy.io,direct
https://mirrors.aliyun.com/goproxy/,direct
你可以根据需要选择合适的代理。
通过以上步骤,你应该能够在 CentOS 上成功配置 Go 语言代理。