[TOC] #### 前言 --- 当我们使用默认官方源时,经常会遇到以下问题  查看镜像配置 ``` brew config ```  #### 切换国内源 ---- ``` /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" ``` #### 4.0 镜像配置 ---- 温馨提示:不要使用阿里云的 Homebrew 源,好久没更新了,而且还不支持 Homebrew 4.0 的镜像源 ##### [清华大学镜像站](https://mirrors.tuna.tsinghua.edu.cn/help/homebrew) ``` # homebrew 4.x 清华大学镜像 最新的 JSON API 安装方式 export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git" export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api" export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles" ``` ##### [中国科学技术大学镜像源](https://mirrors.ustc.edu.cn/help/brew.git.html) ``` # homebrew 4.x 中科大镜像 最新的 JSON API 安装方式 export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api" export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles" ``` 如果 shell 为 zsh,也就是添加 `~/.zshrc` 文件中,然后执行以下命令或重新打开窗口 ``` source ~/.zshrc ``` #### 4.x 以前镜像配置 ---- **Zsh 终端配置** [(阿里云镜像源)](https://developer.aliyun.com/mirror/homebrew) ``` # 替换brew.git: cd "$(brew --repo)" git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git # 替换homebrew-core.git: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git # 应用生效 brew update # 替换homebrew-bottles: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc source ~/.zshrc ``` **恢复 Homebrew 默认配置** ``` # 替换 brew.git cd "$(brew --repo)" git remote set-url origin https://github.com/Homebrew/brew.git # 替换 homebrew-core.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://github.com/Homebrew/homebrew-core.git # 应用生效 brew update # 删除 homebrew-bottles: # 注释掉 .zshrc 中的 HOMEBREW_BOTTLE_DOMAIN source ~/.zshrc ```