一、先查看macOS系统使用的 shell 版本
echo $SHELL
# 输出 /bin/zsh 或者 /bin/bash
- /bin/zsh 对应环境变量文件 ~/.zshrc
- /bin/bash 对应环境变量文件 ~/.bash_profile
以下以 /bin/zsh 为例
二、安装
1、官方源(不建议使用,太慢)
/bin/zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2、国内源
/bin/zsh -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
三、更换下载源
Homebrew主要由4个部分组成:
- brew: 源代码仓库
- homebrew-core: 核心软件仓库
- homebrew-bottles: 预编译二进制软件包
- homebrew-cask: MacOS客户端应用
如果使用 4.x 最新的 JSON API 安装方式
echo '
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api" ' >> ~/.zshrc
#保存配置
source ~/.zshrc
- 还原
vi ~/.zshrc
# 删除上面三行配置
source ~/.zshrc
四、 4.x 以前版本
1、替换brew.git源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git #阿里源
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git #清华源
2、替换homebrew-core.git源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git #阿里源
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git #清华源
3、替换homebrew-bottles源
echo '
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/bottles" ' >> ~/.zshrc
source ~/.zshrc