软件开发国内常用镜像源配置及回退方法(MAC版)

本机本地包镜像配置汇总与官方默认回滚说明

汇总表

工具 当前配置来源 当前配置值 当前生效镜像 / Registry 验证说明 回退方式摘要
pip ~/.config/pip/pip.conf [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple https://pypi.tuna.tsinghua.edu.cn/simple 已确认配置文件内容 删除 index-url 或删除该用户配置文件
npm ~/.npmrc registry=https://registry.npmmirror.com/ https://registry.npmmirror.com/ 已确认配置文件内容 删除 registry= 行,或显式设回官方源
pnpm 与 npm 共用 ~/.npmrc 同 npm 的 registry=https://registry.npmmirror.com/ https://registry.npmmirror.com/ 已通过 pnpm config get registry 验证 回退 npm 配置,或显式设回官方源
yarn Yarn 自身配置 registry=https://registry.npmmirror.com https://registry.npmmirror.com 已通过 yarn config get registry 验证 删除 Yarn 的 registry 配置,或显式设回官方源
Go Go 环境配置 GOPROXY=https://goproxy.cn,direct https://goproxy.cn,direct 已通过 go env GOPROXY 验证 go env -u GOPROXY 或显式写回官方默认值
cargo ~/.cargo/config.toml 使用 replace-with = rsproxy-sparse 并定义 rsproxy 源 sparse+https://rsproxy.cn/index/ 已确认配置文件内容 删除 cargo 镜像相关 source / registries 配置块
rustup ~/.zshrc RUSTUP_DIST_SERVER / RUSTUP_UPDATE_ROOT 指向 rsproxy https://rsproxy.cn / https://rsproxy.cn/rustup 已确认 shell 配置内容 删除两条环境变量并重新加载 shell
uv ~/.config/uv/uv.toml [[index]] url = "https://pypi.tuna.tsinghua.edu.cn/simple" default = true https://pypi.tuna.tsinghua.edu.cn/simple 已确认配置文件内容 删除该 [[index]] 块,或删除用户配置文件
Maven ~/.m2/settings.xml mirror aliyun-public -> https://maven.aliyun.com/repository/public https://maven.aliyun.com/repository/public 已确认配置文件内容,且 effective settings 已生效 删除 <mirror> 块,或删除该用户级 settings.xml
RubyGems gem source 配置 当前仅保留 TUNA RubyGems 源 https://mirrors.tuna.tsinghua.edu.cn/rubygems/ 已通过 gem sources --list 验证 移除 TUNA 源并加回官方源
Bundler ~/.bundle/config BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/: "https://mirrors.tuna.tsinghua.edu.cn/rubygems" https://mirrors.tuna.tsinghua.edu.cn/rubygems 已确认配置文件内容,且 bundle config mirror.https://rubygems.org 已验证 bundle config unset --global ... 或删除对应配置项

pip

当前配置文件

~/.config/pip/pip.conf

当前配置值

ini 复制代码
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

当前生效镜像

https://pypi.tuna.tsinghua.edu.cn/simple

回退到官方默认

如果只想移除用户级覆盖,直接删掉 index-url 这一行即可。

ini 复制代码
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

如果这个文件只用于这一项配置,也可以直接删除整个文件:

bash 复制代码
rm ~/.config/pip/pip.conf

npm

当前配置文件

~/.npmrc

当前配置值

ini 复制代码
registry=https://registry.npmmirror.com/

当前生效 Registry

https://registry.npmmirror.com/

回退到官方默认

方法一:删除 ~/.npmrc 中这一行:

ini 复制代码
registry=https://registry.npmmirror.com/

方法二:显式写回官方源:

bash 复制代码
npm config set registry https://registry.npmjs.org/

如果 ~/.npmrc 只有这一项,也可以直接删除整个文件:

bash 复制代码
rm ~/.npmrc

pnpm

当前配置来源

与 npm 共用 ~/.npmrc

当前配置值

ini 复制代码
registry=https://registry.npmmirror.com/

当前生效 Registry

https://registry.npmmirror.com/

验证说明

已通过 pnpm config get registry 验证当前生效值为 https://registry.npmmirror.com/

回退到官方默认

pnpm 当前按 npm 风格 registry 共用处理,因此最直接的回退方式与 npm 相同:

bash 复制代码
pnpm config set registry https://registry.npmjs.org/

或者回退 ~/.npmrc 中的 registry 配置:

bash 复制代码
rm ~/.npmrc

如果 ~/.npmrc 里还有其他设置,则不要删整个文件,只删除 registry=... 那一行。

yarn

当前生效值

text 复制代码
yarn config get registry
=> https://registry.npmmirror.com

当前生效 Registry

https://registry.npmmirror.com

回退到官方默认

方法一:直接删除 Yarn 的 registry 配置:

bash 复制代码
yarn config delete registry

方法二:显式写回官方源:

bash 复制代码
yarn config set registry https://registry.npmjs.org/

Go

当前生效值

text 复制代码
go env GOPROXY
=> https://goproxy.cn,direct

当前生效代理

https://goproxy.cn,direct

回退到官方默认

更干净的回退方式是移除用户级覆盖:

bash 复制代码
go env -u GOPROXY

如果你更希望显式写回默认值,也可以这样做:

bash 复制代码
go env -w GOPROXY=https://proxy.golang.org,direct

cargo

当前配置文件

~/.cargo/config.toml

当前配置值

toml 复制代码
[source.crates-io]
replace-with = "rsproxy-sparse"

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"

[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

[registries.rsproxy-sparse]
index = "sparse+https://rsproxy.cn/index/"

[net]
git-fetch-with-cli = true

当前生效镜像

核心生效入口是:

toml 复制代码
[source.crates-io]
replace-with = "rsproxy-sparse"

也就是把 crates.io 替换到:

sparse+https://rsproxy.cn/index/

回退到官方默认

如果你只想回退镜像,建议删除下面这些镜像相关配置块,保留与镜像无关的其他配置:

toml 复制代码
[source.crates-io]
replace-with = "rsproxy-sparse"

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"

[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

[registries.rsproxy-sparse]
index = "sparse+https://rsproxy.cn/index/"

如果 ~/.cargo/config.toml 只用于这组镜像设置,也可以直接删除整个文件:

bash 复制代码
rm ~/.cargo/config.toml

rustup

当前配置文件

~/.zshrc

当前配置值

bash 复制代码
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

当前生效地址

  • RUSTUP_DIST_SERVER=https://rsproxy.cn
  • RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup

回退到官方默认

删除 ~/.zshrc 中这两行:

bash 复制代码
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

删除后,需要重新加载 shell:

bash 复制代码
source ~/.zshrc

或者直接打开一个新的终端会话。

uv

当前配置文件

~/.config/uv/uv.toml

当前配置值

toml 复制代码
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
default = true

当前生效索引

https://pypi.tuna.tsinghua.edu.cn/simple

回退到官方默认

删除整个 [[index]] 块即可:

toml 复制代码
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
default = true

如果该文件只用于这一项配置,也可以直接删除整个文件:

bash 复制代码
rm ~/.config/uv/uv.toml

Maven

当前配置文件

~/.m2/settings.xml

当前配置值

xml 复制代码
<mirror>
  <id>aliyun-public</id>
  <name>Aliyun Maven Public</name>
  <url>https://maven.aliyun.com/repository/public</url>
  <mirrorOf>*</mirrorOf>
</mirror>

当前生效镜像

https://maven.aliyun.com/repository/public

补充说明

当前使用的是 mirrorOf=*,覆盖范围比较广。对个人机器拉公共依赖通常没问题,但如果后续要接私有仓库,通常需要把匹配范围改窄。

回退到官方默认

删除 ~/.m2/settings.xml 中这段 <mirror>...</mirror> 即可。

如果这个用户级 settings.xml 只包含这一项镜像设置,也可以直接删除整个文件:

bash 复制代码
rm ~/.m2/settings.xml

RubyGems

当前生效值

text 复制代码
gem sources --list
=> 仅显示 https://mirrors.tuna.tsinghua.edu.cn/rubygems/

当前生效源

https://mirrors.tuna.tsinghua.edu.cn/rubygems/

回退到官方默认

先移除当前镜像源,再加回官方源:

bash 复制代码
gem sources --remove https://mirrors.tuna.tsinghua.edu.cn/rubygems/
gem sources --add https://rubygems.org/

回退后可以再次检查:

bash 复制代码
gem sources --list

Bundler

当前配置文件

~/.bundle/config

当前配置值

yaml 复制代码
BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/: "https://mirrors.tuna.tsinghua.edu.cn/rubygems"

当前生效镜像

https://mirrors.tuna.tsinghua.edu.cn/rubygems

回退到官方默认

推荐直接取消全局镜像配置:

bash 复制代码
bundle config unset --global mirror.https://rubygems.org

如果需要手动编辑文件,则删除 ~/.bundle/config 中这一行:

yaml 复制代码
BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/: "https://mirrors.tuna.tsinghua.edu.cn/rubygems"

如果 ~/.bundle/config 只包含这一项镜像设置,也可以直接删除整个文件:

bash 复制代码
rm ~/.bundle/config
相关推荐
老兵发新帖6 小时前
ast-grep
软件工程
无籽西瓜a7 小时前
【西瓜带你学设计模式 | 第十四期 - 享元模式】享元模式 —— 内外状态分离与对象共享实现、优缺点与适用场景
java·设计模式·软件工程·享元模式
qq_411262427 小时前
ESP32-C5 软件配置MAC 地址
macos
鸠摩智首席音效师7 小时前
如何在 MacOS 上安装 PostgreSQL ?
数据库·macos·postgresql
花千树-0108 小时前
IndexTTS2 在 macOS 性能最佳设置(M1/M2/M3/M4 全适用)
人工智能·深度学习·macos·ai·语音识别·ai编程
zhensherlock1 天前
Protocol Launcher 系列:Agenda 优雅组织你的想法与日程
javascript·macos·ios·typescript·node.js·mac·ipad
ipy2Tf8WP1 天前
全程用 Claude Code 搓了一个 macOS 原生应用:SkillDeck
macos
eLIN TECE1 天前
Mac安装Redis步骤
redis·macos·bootstrap
独隅1 天前
在 MacOS 上部署 Keras 模型的全面指南
人工智能·macos·keras