MacBook Pro安装Homebrew慢的问题解决方案

872 阅读1分钟

MacBook Pro作为开发工具使用的话,一定离不开一个很重要的工具,Homebrew
但是国内安装Homebrew一直很慢,通过官网的方案使用install.sh脚本安装一般git clone的速度都是几Kb/s,而且必须要保持网络环境的稳定,否则一不小心就要重新安装。

下面这个方法,可以使安装Homebrew变的非常快

执行官网命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

一般都会出现如下错误

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out

遇到这种情况,请将Mac电脑的DNS,修改成8.8.8.8

然后执行官网命令,不会出现443的问题,但是会非常缓慢,很难安装成功,所以,需要是修改一下Homebrew的下载源

下载install.sh的安装脚本

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh >> brew_install

打开install.sh脚本,修改Homebrew源地址

将默认的源
BREW_REPO = "https://github.com/Homebrew/brew"    

修改为  
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git"

执行安装

/bin/bash brew_install

安装过程中,会停止在下面的位置,不要慌,手动停止就可以了

==> Tapping homebrew/core Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

更改homebrew-core的源

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

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