0%

Mac下加快HomeBrew下载速度

使用代理

本机socks5 代理端口为 127.0.0.1:1086

在 ~/.bash_profile 中添加如下配置即可

1
alias brews='all_proxy=socks5://127.0.0.1:1086 brew '

之后使用 brews 代替 brews

切换镜像

1.使用清华源

替换默认源

第一步:替换现有上游

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

第二步:使用homebrew-science或者homebrew-python(两个模块不存在,已被合并进core)

1
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-science"
1
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-science.git

1
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-python"
1
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-python.git
1
cd
1
brew update

替换Homebrew Bottles源

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

2.在清华源失效或宕机时可以切换回官方源

第一步:重置brew.git

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

第二步:重置homebrew-core.git

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

第三步:注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源。 重启bash或让bash重读配置文件。