一、查看当前Homebrew 镜像源
- 方法1
1
2
3brew config
# 查看现在镜像源
# ORIGIN:https://github.com/Homebrew/brew.git 之前未操作过则会显示这个链接,也就是官方镜像源 - 方法2
1
2
3
4
5
6
7
8# brew.git镜像源
git -C "$(brew --repo)" remote -v
# homebrew-core.git镜像源
git -C "$(brew --repo homebrew/core)" remote -v
# homebrew-cask.git镜像源
git -C "$(brew --repo homebrew/cask)" remote -v
二、替换源
国内镜像地址
- 方法1
1
2
3
4
5
6
7# 替换 brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换 homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git - 方法2
1
2
3
4
5
6git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git - 方法3
1
2
3
4
5
6
7
8
9if [ $SHELL = "/bin/bash" ] # 如果你的是bash
then
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.bash_profile
source ~/.bash_profile
elif [ $SHELL = "/bin/zsh" ] # 如果用的shell 是zsh 的话
then
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.zshrc
source ~/.zshrc
fi
三、查看是否替换成功
1 | brew config |
如果替换成功后,进行brew update就可以了
四、恢复原有镜像源的方法
- 如果需要恢复原有镜像源的话(国内镜像源突然不能用了或版本不够新)
1
2
3
4
5
6
7
8
9git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 找到 ~/.bash_profile 或者 ~/.zshrc 中的HOMEBREW_BOTTLE_DOMAIN 一行删除
brew update
参考: