解决Mac上国内安装HomeBrew慢的解决方法。以下git
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码
获取官网脚本并保存名为 brew_install:raw.githubusercontent.com/Homebrew/in…github
打开 brew_install 文件,修改以下:shell
找到以下代码:ruby
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
复制代码
更改成:bash
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze
CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze
复制代码
注意: 新版本HomeBrew可能没有CORE_TAP_REPO
这句代码,若是没有不用新增。 若是这个镜像有问题的话,能够换成其余源。app
打开终端容许脚本curl
/usr/bin/ruby brew_install
复制代码
若是此时脚本应该停在ui
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
复制代码
出现这个缘由是由于源不通,代码来不下来,解决方法就是更换国内镜像源:url
手动执行下面这句命令,更换为中科院的镜像:spa
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
复制代码
而后把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
复制代码
执行更新,成功:
brew update
复制代码
最后用这个命令检查无错误:
brew doctor
复制代码
至此HomeBrew就安装完成了。
直接使用 Homebrew 还须要更改默认源。如下是将默认源替换为国内 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/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
复制代码
bash(默认 shell)用户:
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
复制代码