当前位置: 首页 > news >正文

Go更换国内源配置环境变量

背景

        要在中国境内下载和使用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

另外通过环境变量永久配置

linux/mac

# 设置你的 bash 环境变量
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.profile && source ~/.profile# 如果你的终端是 zsh,使用以下命令
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.zshrc && source ~/.zshrc官方说明
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for specified repos (optional)
export GOPRIVATE=git.mycompany.com,github.com/my/private

windows

1. 右键 我的电脑 -> 属性 -> 高级系统设置 -> 环境变量
2. 在 “[你的用户名]的用户变量” 中点击 ”新建“ 按钮
3. 在 “变量名” 输入框并新增 “GOPROXY”
4. 在对应的 “变量值” 输入框中新增 “https://goproxy.io,direct”
5. 最后点击 “确定” 按钮保存设置官方说明
# Set the GOPROXY environment variable
$env:GOPROXY = "https://goproxy.io,direct"
# Set environment variable allow bypassing the proxy for specified repos (optional)
$env:GOPRIVATE = "git.mycompany.com,github.com/my/private"

配置完成后,你就可以快速下载和使用Go的包了。


http://www.mrgr.cn/news/1581.html

相关文章:

  • Baumer工业相机堡盟工业相机如何通过BGAPISDK初始化时过滤其它非Baumer相机(C#)
  • 鸿萌数据恢复服务:SQL Server 中的“PFS 可用空间信息不正确”错误
  • 网络安全实训第五天(主机系统渗透)
  • DAX(Data Analysis Expressions)数据建模底层原理是什么?BI分析工具的底层及应用场景的分析
  • 节省IO的小技巧:GD32 MCU如何使用一个GPIO实现串口半双工收发
  • Vue 3中deep属性的深度解析:ref与reactive的不同表现
  • Golang | Leetcode Golang题解之第352题将数据流变为多个不相交区间
  • 16:【stm32】I2C的使用一:I2C片上外设的使用
  • 记录一次edu web端渗透测试实录
  • C#与其它编程语言有什么区别,以及相关优势有哪些
  • Windows禁止应用联网
  • Awesome-Chinese-LLM:收集和梳理中文LLM相关的开源模型、应用、数据集及教程等资料
  • Android about event log
  • Java设计模式之中介者模式
  • EmguCV学习笔记 VB.Net 3.1 直线
  • python工具--mysql2doris的datax json生成工具
  • C语言整数溢出的问题
  • 智能驾驶时代的中控屏UI设计创新
  • android13隐藏调节声音进度条下面的设置按钮
  • 开放式耳机哪种好用?开放式种草测评!