- 首先第一种(最简单的,但只适用于能翻墙的玩家):直接复制官方的安装命令即可.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.第二种可以完美安装
- 获取安装文件
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
此处需要保证GitHub的资源域名raw.githubusercontent.com能够正常访问,但大多情况下是访问不了的,通常是因为DNS污染导致的,可以通过手动修改hosts文件解决。https://www.ipaddress.com/可通过这个网站获取到真实地址,然后手动修改到hosts里面即可。
- 更改brew_install文件中的链接资源,将原有的链接资源替换成国内的镜像资源
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
更改为
BREW_REPO = “git://mirrors.ustc.edu.cn/brew.git“.freeze
运行brew_install进行安装
/usr/bin/ruby ~/brew_install
上面会卡在homebrew-core的地方,需要手动获取下:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask --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
cd "$(brew --repo)/Library/Taps/caskroom/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
- 替换Bottle源
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
更新命令
brew update检测命令
brew doctor