解决Mac下安装Homebrew慢的问题

国内安装Homebrew很慢,可以使用下面的方法:

curl -fsSL https://gitee.com/xueweihan/codes/vfrgh7z8qcjlx1ubwt6nk71/raw\?blob_name\=brew_install.sh >> brew_install

先把安装文件保存到brew_install,然后修改其中的仓库地址,打开 brew_install 文件,把
BREW_REPO后面引号内的地址改为:

https://mirrors.ustc.edu.cn/brew.git

或者

https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

如果有CORE_TAP_REPO,则把引号内的地址改为:

https://mirrors.ustc.edu.cn/homebrew-core.git

或者

https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

如果没有CORE_TAP_REPO也不用新增。
执行下面的命令开始安装:

/usr/bin/ruby brew_install

安装到显示:

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

在这里插入图片描述
时,可能会比较慢了,此时中断安装。手动执行:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

上面的git地址可以使用前面CORE_TAP_REPO的两个地址中任意一个。

然后再把homebrew-core的地址也改为国内的镜像地址:

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

或者:

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

安装完成后再更新一下:

brew update

检测一下是否有问题:

brew doctor

在这里插入图片描述
我的就检测到一些警告,不过不影响。

为了让Homebrew安装软件时速度更快,需要替换Homebrew-bottles的地址,使用:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles

临时替换。如果Mac是终端用的bash,使用

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

进行永久替换,如果终端用的是zsh,把bash_profile改为zshrc即可。

参考:
https://www.zhihu.com/question/35928898
https://blog.csdn.net/DiyHzp/article/details/90763558
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章