homebrew的源问题

------ 砰,几年前的子弹射过来了

多年之前 我一直在homebrew的源问题中 游离,真的是游离 每一次没都没有完整解决 这个问题,Mac上很多软件库都需要依赖homebrew来管理和安装。有点想node的npm,python的pip的感觉。尽管在2018年的时候我从场景使用macport 替换它来实现ffmmp(不会拼写了) rtmp推流服务,但最终还是觉得homebrew相对活跃成熟。

时至今日,我再次在这个问题上卡住,以为我需要构建springboot项目,从Maven迁移到Gradle,虽然我知道IDEA已经集成了Gradle,但是我依然想尝试本机安装一下试试。

------ 砰,几年前的子弹射过来了,这一次我选择硬钢了,我要彻彻底底的换掉源。

中间的问题先不说了,最后的最后的问题:

复制代码
(base) ➜  homebrew git:(stable) brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Suspicious https://github.com/Homebrew/brew git origin remote found.
The current git origin is:
  https://mirrors.ustc.edu.cn/brew.git

With a non-standard origin, Homebrew won't update properly.
You can solve this by setting the origin remote:
  git -C "/usr/local/Homebrew" remote set-url origin https://github.com/Homebrew/brew

ds给我了一些提示:

Homebrew 源被部分修改了,指向了中科大的镜像 (ustc.edu.cn),但这可能不是完整或正确的配置。brew doctor 的警告很明确:非标准的 git 远程地址会导致更新问题

让我们来安全、彻底地修复方案会 将 Homebrew 重置为官方源,再统一、正确地切换到国内镜像

🔧 完整修复方案:重置并统一配置镜像

严格按照顺序执行以下命令:

第一步:重置所有仓库到官方源
bash 复制代码
# 1. 重置主仓库 (brew)
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# 2. 重置核心仓库 (homebrew-core) - 确保它在正确位置
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

# 3. 重置你已安装的其他仓库(services, nginx等)
git -C "$(brew --repo homebrew/services)" remote set-url origin https://github.com/Homebrew/homebrew-services.git
# 如果有 homebrew-nginx,也执行类似命令
第二步:清理并更新到干净状态
bash 复制代码
# 清理旧的下载缓存
brew cleanup

# 尝试使用官方源更新(可能较慢,仅用于验证)
brew update

执行完 brew update 后,观察是否还有错误。如果没有,说明重置成功。

第三步:统一切换到清华大学镜像源

执行下面这一组完整命令 ,一次性设置好所有必要的环境变量。请逐行复制并执行

bash 复制代码
# 1. 设置核心环境变量 (解决你之前遇到的错误)
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_SERVICES_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"

# 2. 更新 git 远程地址以匹配环境变量
git -C "$(brew --repo)" remote set-url origin $HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo homebrew/core)" remote set-url origin $HOMEBREW_CORE_GIT_REMOTE
git -C "$(brew --repo homebrew/homebrew-services)" remote set-url origin $HOMEBREW_SERVICES_GIT_REMOTE

# 3. 执行更新,现在应该通过国内镜像了
brew update

# 4. 运行诊断,警告应消失
brew doctor
第四步:永久生效配置

将以下内容 一次性添加 到你的 ~/.zshrc 文件末尾:

bash 复制代码
# Homebrew 国内镜像配置 (清华大学源)
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_SERVICES_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"

然后执行 source ~/.zshrc 使其生效。

📝 验证与后续操作

修复后,请验证:

  1. 运行 brew doctor:之前的警告应该消失。
  2. 运行 brew update:应该能快速、成功地更新。
  3. 测试安装 :尝试安装一个小工具测试,例如 brew install wget

💎 最终建议

1、千万不要相信 完全重置Homebrew,你不知道这么做有多愚蠢。

2、你要相信国内源大部分也是套壳的,核心还是请求国外的东西,快?不慢就行了。

3、core目录没了?

相关推荐
梁辰兴3 天前
计算机网络基础:以太网的 MAC 层
网络·计算机网络·macos·计算机·mac·以太网·梁辰兴
老臣软件4 天前
macOS 下载太慢?问题可能不在网速
经验分享·macos·mac·实用软件·网络下载管理器
不拱地的猪10 天前
Matplotlib 的字体参数设置方法(MAC OSX)
python·mac·matplotlib·字体设置·文中显示中文
老臣软件10 天前
研究 TikTok 爆款的人,一定要懂这类下载工具
mac
Wcowin15 天前
OneClip 开发经验分享:从零到一的 macOS 剪切板应用开发
mac·swift·粘贴板
Wcowin17 天前
【自荐】OneClip—— 一款简单专业的 macOS 剪贴板管理工具
mac·swift·粘贴板
tobebetter952720 天前
How to use homebrew on mac
macos·homebrew
亚林瓜子22 天前
git中移除.DS_Store文件夹和相关文件
git·mac·ignore·.ds_store
喵霓22 天前
mac—安装wget过程
mac