Homebrew是macOS下的package manager,由于网络问题,直接安装可能比较痛苦。
本文参考自:HomeBrew 官方安装太慢而失败?这么搞就行.(转载)
由于安装脚本已经由ruby改为shell,原来的方法需要修改,分享如下。
一、安装Homebrew
1. 首先运行
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh > install.sh
把安装脚本下载下来。如果用curl获取失败,可以手动打开地址把脚本复制下来。
2. 然后打开install.sh,把第33行的
BREW_REPO="https://github.com/Homebrew/brew"
改为中科大的mirror:
BREW_REPO="git://mirrors.ustc.edu.cn/brew.git"
3. 然后执行安装脚本,根据提示按Enter、输入密码。
/bin/bash install.sh
4. 如果出现
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
卡住不动或者速度很慢,可以用Ctrl+C结束,或者等到出现网络错误。然后执行
cd /usr/local/Homebrew
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
brew update
出现 Already up-to-date 安装成功。
二、设置brew安装源
1. 设置brew install源(根据自己用bash或zsh选择)
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
或
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
2. 设置brew cask源 (optional)
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask --depth=1
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
三、卸载Homebrew
如果想卸载Homebrew,执行
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
即可。
如果用curl获取失败,手动打开地址把脚本复制下来,然后执行
/usr/bin/ruby uninstall