当前位置: 首页 > 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.lryc.cn/news/427688.html

相关文章:

  • 澎湃认证显实力,浪潮信息存储兼容新篇章
  • Leetcode 3255. Find the Power of K-Size Subarrays II
  • Kotlin学习02-变量、常量、整数、浮点数、操作符、元组、包、导入
  • C++的模板简介
  • 树莓派5 笔记25:第一次启动与配置树莓派5_8G
  • Melittin 蜂毒肽;GIGAVLKVLT TGLPALISWI KRKRQQ
  • day32
  • 【clickhouse】 使用 SQLAlchemy 连接 ClickHouse 数据库的完整指南
  • 按键收集单击,双击和长按
  • 进程的异常终止
  • 并发编程 | Future是如何优化程序性能
  • Oracle笔记
  • LVS+Keepalived 双机热备
  • Web Image scr图片从后端API获取基本实现
  • 2024音频剪辑指南:探索四大高效工具!
  • “CSS”第一步——WEB开发系列13
  • IEEE802网络协议和标准
  • vulnhub靶机 DC-9(渗透测试详解)
  • javaweb的新能源充电系统pf
  • 如何在桌面同时展示多个窗口
  • The Sandbox 游戏制作教程(第 5 部分):创建基于分类的系统
  • HTML浏览器缓存(Browser Cache)
  • 短剧APP系统,推动短剧市场发展
  • 嵌入式 | 嵌入式 Linux 系统使用摄像头
  • C 开源库之cJSON
  • ROW_NUMBER(), RANK(), DENSE_RANK() SQL排序函数图文详解
  • Spring IoCDI(下)—DI的尾声
  • 仕考网:考外省公务员可以调回本地吗?
  • 《工厂模式在软件开发中的深度剖析与应用》
  • 双向通信之Websocket