安装
1. 官方网址(https://brew.sh/)给出的方案是这样的:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
按照此方法速度很慢
2. 获取官网的install文件(https://raw.githubusercontent.com/Homebrew/install/master/install)另存为brew_install
3. 更改里面的源,将
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
更改为
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
CORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze
其中新版本Homebrew第二行可能不存在,只需要改第一行。
4. 执行脚本,利用ruby执行
/usr/bin/ruby brew_install
如果终端停留在:
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
说明源不通,进行换源:
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)"
sudo git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
sudo git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
更新brew(也可不更新)
brew update
利用这个命令检查无误:
brew --version # 检查版本
brew doctor
更改默认源
直接使用homebrew还需更改默认源为清华源USTC
替换核心软件仓库
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
sudo git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替换cask软件仓库(提供macOS应用和大型二进制文件)
cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
sudo git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替换bottles源(Homebrew预编译二进制软件包
sudo echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
6. brew常用命令