要在中国境内下载和使用Go编程语言的包,可以使用国内的Go模块代理来加速下载速度。以下是一些常见的国内Go模块代理源以及如何切换到这些源的方法:
常见国内Go模块代理源
七牛云(Qiniu)
https://goproxy.cn
阿里云(Alibaba Cloud)
https://mirrors.aliyun.com/goproxy/
清华大学(Tsinghua University)
https://goproxy.tuna.tsinghua.edu.cn
切换Go模块代理源的方法
通过环境变量配置
在终端中执行以下命令:
go env -w GOPROXY=https://goproxy.cn,direct
通过配置文件配置
你也可以在Go的配置文件中手动修改GOPROXY的值。找到并编辑go的配置文件(通常位于$HOME/.config/go/env),添加或修改以下行:
GOPROXY=https://goproxy.cn,direct
以下是使用七牛云源的示例:
go env -w GOPROXY=https://goproxy.cn,direct
类似的,你可以根据需要选择其他代理源,例如:
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
或
go env -w GOPROXY=https://goproxy.tuna.tsinghua.edu.cn,direct
配置完成后,你就可以快速下载和使用Go的包了。
1804

被折叠的 条评论
为什么被折叠?



