一、获取最新安装脚本到本地编辑
cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
编辑 brew_install 文件
# This script installs to /usr/local only. To install elsewhere (which is # unsupported) you can untar https://github.com/Homebrew/brew/tarball/master # anywhere you like. HOMEBREW_PREFIX = "/usr/local".freeze HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze HOMEBREW_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze # BREW_REPO = "https://github.com/Homebrew/brew".freeze BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
注释掉
BREW_REPO = "https://github.com/Homebrew/brew".freeze
新增行BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
二、执行修改后的脚本安装
/usr/bin/ruby ~/brew_install
- 当出现
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
就不用等了...等不到的... Command + C
停止cd "$(brew --repo)/Library/Taps/"
mkdir homebrew
cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
- 继续执行
/usr/bin/ruby ~/brew_install
- 看到
Installation successful!
就安装成功了
三、修改 Homebrew 源为国内镜像
替换 Homebrew 默认源
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
替换 homebrew-core 源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
四、brew更新
brew update
五、设置 bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile