更换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

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

相关推荐
geneculture6 分钟前
技术-工程-管用养修保-智能硬件-智能软件五维黄金序位模型
大数据·人工智能·算法·数学建模·智能硬件·工程技术·融智学的重要应用
北漂老男孩27 分钟前
Flink Table API 编程入门实践
大数据·flink·学习方法
TGITCIC2 小时前
数据基座觉醒!大数据+AI如何重构企业智能决策金字塔(上)
大数据·ai大模型·ai agent·ai大数据·大数据ai·大模型落地·企业ai落地
SSH_55233 小时前
MacOs 安装局域网 gitlab 记录
elasticsearch·macos·gitlab
JZC_xiaozhong3 小时前
权限分配不合理如何影响企业运营?
大数据·权限管理·数据集成与应用集成·iam 用户中心·企业权限分配·企业权限控制·it系统管理员
Matrix703 小时前
大数据量下的数据修复与回写Spark on Hive 的大数据量主键冲突排查:COUNT(DISTINCT) 的陷阱
大数据·hive·spark
TDengine (老段)4 小时前
TDengine 运维——巡检工具(安装工具)
大数据·运维·数据库·物联网·时序数据库·tdengine·涛思数据
TDengine (老段)4 小时前
TDengine 运维——巡检工具(定期检查)
java·大数据·运维·物联网·时序数据库·tdengine·涛思数据
哲讯智能科技5 小时前
SAP Business One:无锡哲讯科技助力中小企业数字化转型的智慧之选
大数据·人工智能