概念:

  • Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷

M1 MacBook安装步骤:

  1. Arm版Homebrew的安装.根据官方规划,ARM 版 Homebrew 必须安装在 /opt/homebrew 路径下,而非此前的 /usr/local/Homebrew。由于官方的安装脚本还未更新,可以通过如下命令手动安装
# 切换到/opt目录
cd /opt
# 创建homebrew目录
mkdir homebrew
# 修改目录所属用户
sudo chown -R $(whoami) /opt/homebrew
# 安装Arm版Homebrew
curl -L <https://github.com/Homebrew/brew/tarball/master> | tar xz --strip 1 -C homebrew
#查看brew的配置信息
./brew config
  1. X86版Homebrew的安装
#指定-x86_64安装也就是经过转译,国内源
arch -x86_64 /bin/zsh -c "$(curl -fsSL <https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh>)"
#查看brew的配置信息
./brew config
  1. 设置环境变量并区分ARM和Inter架构
$ vim ~/.zshrc

# x86->abrew
export PATH="/usr/local/bin:$PATH"
alias abrew='arch -x86_64 /usr/local/bin/brew'

# arm->brew
export PATH="/opt/homebrew/bin:$PATH"
alias brew='/opt/homebrew/bin/brew'
  1. Homebrew换源
    更换Arm版的源:
# 替换brew.git
cd "$(brew --repo)"
git init
git remote add origin "<https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git>"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

cd "$(brew --repo)/Library/"
mkdir Taps
cd Taps

git clone "<https://mirrors.ustc.edu.cn/homebrew-core.git>"
git clone "<https://mirrors.ustc.edu.cn/homebrew-cask.git>"

git reset --hard origin/master

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

cd "$(brew --repo)"
git reset --hard origin/master

#检验是否成功
brew update

更换X86版本的源:

# 替换brew.git
cd "$(abrew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

# 替换homebrew-core.git
cd "$(abrew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

#检验是否成功
abrew update
  1. 最后还要在~/.zshrc中加入以下内容来替换Homebrew Bottles源,Arm版和X86版的一样:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

source ~/.zshrc