[TOC] #### 前言 --- 當(dāng)我們使用默認(rèn)官方源時(shí),經(jīng)常會遇到以下問題 ![](https://img.itqaq.com/art/content/eba4b7e87d4e7c2d7503ae0672b5833f.png) 查看鏡像配置 ``` brew config ``` ![](https://img.itqaq.com/art/content/bb406b4356deabe827fbcc56c6edb690.png) #### 切換國內(nèi)源 ---- ``` /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" ``` #### 4.0 鏡像配置 ---- 溫馨提示:不要使用阿里云的 Homebrew 源,好久沒更新了,而且還不支持 Homebrew 4.0 的鏡像源 ##### [清華大學(xué)鏡像站](https://mirrors.tuna.tsinghua.edu.cn/help/homebrew) ``` # homebrew 4.x 清華大學(xué)鏡像 最新的 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" ``` ##### [中國科學(xué)技術(shù)大學(xué)鏡像源](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` 文件中,然后執(zhí)行以下命令或重新打開窗口 ``` 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 # 應(yīng)用生效 brew update # 替換homebrew-bottles: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc source ~/.zshrc ``` **恢復(fù) Homebrew 默認(rèn)配置** ``` # 替換 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 # 應(yīng)用生效 brew update # 刪除 homebrew-bottles: # 注釋掉 .zshrc 中的 HOMEBREW_BOTTLE_DOMAIN source ~/.zshrc ```