更换Homebrew 源

以下是查看和修改 Homebrew 源的详细步骤,适用于需要切换到国内镜像以加速下载的场景:

1. 查看当前 Homebrew 源

bash 复制代码
# 查看 brew 主仓库地址
git -C "$(brew --repo)" remote get-url origin

# 查看 homebrew-core 仓库地址
git -C "$(brew --repo homebrew/core)" remote get-url origin

# 查看 homebrew-cask 仓库地址(如安装了 cask)
git -C "$(brew --repo homebrew/cask)" remote get-url origin

2. 修改为国内镜像源(以中科大镜像为例)

bash 复制代码
# 设置 brew 主仓库
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git

# 设置 homebrew-core 仓库
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 设置 homebrew-cask 仓库(可选)
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# 刷新缓存
brew update

3. 其他国内镜像源选项

  • 清华大学镜像

    bash 复制代码
    # brew 主仓库
    git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
    
    # homebrew-core
    git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
    
    # homebrew-cask
    git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
  • 阿里云镜像

    bash 复制代码
    # brew 主仓库
    git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    
    # homebrew-core
    git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

4. 恢复为官方源

bash 复制代码
# brew 主仓库
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

# homebrew-core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

# homebrew-cask
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

5. 验证修改是否成功

再次运行步骤 1 的命令,确认输出的仓库地址已变更为所选镜像源。

注意事项

  1. 中科大镜像限制:中科大镜像仅支持 macOS 和 Linux 系统,不支持 Windows。

  2. 环境变量影响 :如果设置了 HOMEBREW_BREW_GIT_REMOTEHOMEBREW_CORE_GIT_REMOTE 环境变量,可能会覆盖手动设置的源。检查并删除这些环境变量:

    bash 复制代码
    unset HOMEBREW_BREW_GIT_REMOTE
    unset HOMEBREW_CORE_GIT_REMOTE
  3. 更新问题 :切换镜像后若遇到更新失败,可尝试清除缓存并重新更新:

    bash 复制代码
    brew cleanup
    brew update --force

根据网络情况选择合适的镜像源,国内推荐使用中科大或清华的镜像。

相关推荐
夜斗小神社3 小时前
【黑马SpringCloud微服务开发与实战】(九)elasticsearch基础
elasticsearch·spring cloud·微服务
Pitayafruit5 小时前
程序员的大数据修炼之道01:建立你的大数据知识体系
大数据
数据与人工智能律师5 小时前
智能合约漏洞导致的损失,法律责任应如何分配
大数据·网络·人工智能·算法·区块链
亅-丿-丶丿丶一l一丶-/^n9 小时前
deep research|从搜索引擎到搜索助手的实践(一)
人工智能·搜索引擎·deep research
AIbase20249 小时前
大模型对比评测:Qwen2.5 VS Gemini 2.0谁更能打?
搜索引擎
Elastic 中国社区官方博客10 小时前
用于 UBI 的 Elasticsearch 插件:从搜索查询中分析用户行为
大数据·数据库·elasticsearch·搜索引擎·全文检索
wdfk_prog10 小时前
实战指南:如何将Git仓库中的特定文件夹及其历史完整迁移到另一个仓库
大数据·linux·运维·笔记·git·学习·elasticsearch
Yzxs00910 小时前
【8月优质EI会议合集|高录用|EI检索稳定】计算机、光学、通信技术、电子、建模、数学、通信工程...
大数据·人工智能·算法·计算机视觉·信息与通信
阿里云大数据AI技术11 小时前
DataWorks千万级任务调度与全链路集成开发治理赋能智能驾驶技术突破
大数据·数据库·数据挖掘
zxsz_com_cn13 小时前
智能化设备维护:开启高效运维新时代
大数据·数据库·人工智能