更新于 

HomeBrew换源

起因

想安装yarn,于是执行:

brew install yarn

结果:

Error: 
homebrew-core is a shallow clone.
homebrew-cask is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

按照提示执行:

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

接着提示:

fatal: 无法访问 'https://github.com/Homebrew/homebrew-core/'
Failed to connect to github.com port 443: Operation timed out

github的访问被神秘力量拒绝了,操作超时。

换源

为解决这个问题,决定换源。USTC Mirror 帮助文档

替换Homebrew Core 源

替换 USTC 镜像:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

重置为官方地址:

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

替换Homebrew Cask 源

替换USTC镜像:

cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

重置为官方源:

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

替换Homebrew Cask Versions 源

替换为 USTC 镜像:

cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask-versions
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask-versions.git

重置为官方地址:

cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask-versions
git remote set-url origin https://github.com/Homebrew/homebrew-cask-versions.git

替换Homebrew Bottles 源

说明:Homebrew 预编译二进制软件包

在运行 brew 前设置环境变量 HOMEBREW_BOTTLE_DOMAIN ,值为 https://mirrors.ustc.edu.cn/homebrew-bottles

对于bash用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

对于zsh用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc