Mac m1 安装Homebrew并设置镜像
arm版本homebrew
cd /opt # 切换到 /opt 目录
mkdir homebrew # 创建 homebrew 目录
sudo chown -R $(whoami) /opt/homebrew # 给目录权限
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew # 安装
intel版本homebrew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # 安装
让两个版本共存
sudo vim ~/.zshrc #添加以下内容
alias abrew='/opt/homebrew/bin/brew' # ARM Homebrew
alias ibrew='arch -x86_64 /usr/local/bin/brew' # X86 Homebrew
path=('/opt/homebrew/bin' $path)
export PATH
source ~/.zshrc
安装完成,查看版本
abrew -v
ibrew -v
设置镜像(中科大)
arm版本设置镜像
cd "$(abrew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(abrew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
intel版本设置镜像
cd "$(ibrew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(ibrew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
查看homebrew源
# 查看arm版本
cd "$(abrew --repo)" && git remote -v
cd "$(abrew --repo homebrew/core)" && git remote -v
# 查看intel版本
cd "$(ibrew --repo)" && git remote -v
cd "$(ibrew --repo homebrew/core)" && git remote -v
以上已替换镜像,如要恢复默认源,执行以下命令
# arm版本恢复
git -C "$(abrew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(abrew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(abrew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
abrew update
# intel版本恢复
git -C "$(ibrew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(ibrew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(ibrew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
abrew update
homebrew-bottles配置只能手动删除,
vim ~/.zshrc
把export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
删除,然后执行
source ~/.bash_profile
homebrew 基础使用
arm版本用abrew,intel版本用ibrew
1.查看Homebrew命令:abrew help
/ ibrew help
2.安装任意包:abrew install <packageName>
/ ibrew install <packageName>
3.卸载任意包:abrew uninstall <packageName>
/ ibrew uninstall <packageName>
4.查询可用包:abrew search <packageName>
/ ibrew search <packageName>
5.查询已安装包列表:abrew list
/ ibrew list
6.查看任意包信息:abrew info <packageName>
/ ibrew info <packageName>
7.更新Homebrew:abrew update
/ ibrew update
8.查看brew版本:abrew -v
/ ibrew -v