一、官方
1、前提
- Mac安装Homebrew的前提条件:
- 64bit Intel CPU或Apple Silicon CPU(M1)
- macOS Mojave(10.14)或更高版本
- 安装Xcode命令行工具(Command Line Tools for Xcode)
- 可以通过命令行
xcode-select --install
安装
- shell(比如bash或zsh)
2、安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
二、其他安装方法
1、安装homebrew-core
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
2、安装homebrew-cask
cd "$(brew --repo)/Library/Taps/homebrew/"
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
三、源
- 为了加速以后使用Homebrew安装其他软件的过程,建议设置软件源为国内源。
1、查看源
cd "$(brew --repo)" && git remote -v
cd "$(brew --repo homebrew/core)" && git remote -v
cd "$(brew --repo homebrew/cask)" && git remote -v
2、设置源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update
3、设置bottles镜像
- 从macOS Catalina(10.15.x) 版开始,Mac使用
zsh
作为默认shell,使用的配置文件:.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zprofile
source ~/.zprofile
- 如果是以前的macOS版本,Mac使用
bash
作为默认shell,使用的配置文件:.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
4、重置为官方源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
vi ~/.zprofile
source ~/.zprofile
vi ~/.bash_profile
source ~/.bash_profile
brew update
四、卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
五、直接使用中科大的源
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"