安装 ARM 版 Homebrew
ARM版Homebrew需要安装在/opt/homebrew路径下,早期的时候需要手动创建目录执行命令,目前使用最新脚本不需要手动操作。直接执行:
1
|
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
|
然后还需设置环境变量,具体操作步骤如下,一定要仔细阅读。
PS: 终端类型根据执行命令echo $SHELL显示的结果:
/bin/bash => bash => .bash_profile
/bin/zsh => zsh => .zprofile
如果遇到环境变量无效问题,建议回过头来查看终端类型,再做正确的设置。
从 macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认Shell,使用.zprofile,所以对应命令:
1
2
|
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
|
如果是macOS Mojave 及更低版本,并且没有自己配置过zsh,使用.bash_profile:
1
|
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile eval "$(/opt/homebrew/bin/brew shellenv)"
|
安装 X86 版 Homebrew
因为目前很多软件包没有支持ARM架构,我们也可以考虑使用x86版的Homebrew。
在命令前面添加arch -x86_64,就可以按 X86 模式执行该命令,比如:
1
|
arch -x86_64 /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
|
多版本共存
如果你同时安装了 ARM 和 X86 两个版本,那你需要设置别名,把命令区分开。
同样是.zprofile或者.bash_profile里面添加:
至于操作哪个文件,请参考前文关于终端类型的描述,下文如有类似文字,保持一样的操作。
1
2
|
alias abrew='arch -arm64 /opt/homebrew/bin/brew'
alias ibrew='arch -x86_64 /usr/local/bin/brew'
|
abrew、ibrew可以根据你的喜好自定义。
然后再执行source ~/.zprofile或source ~/.bash_profile命令更新文件。
设置镜像
注意:本文中的安装脚本会设置中科大源镜像,如果你也想设置cask和bottles的镜像,请按下面注释部分选择执行代码。
执行时根据实际情况修改"$(brew --repo)"代码中的brew。
意思是如果你只是使用一个版本Homebrew,直接执行命令即可,如果你想多个版本共存或者使用了别名,就把brew关键字替换为别名名称,如前面的abrew、ibrew。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# brew
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# cask
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# bottles for zsh 和下面2选1
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile
# bottles for bash 和上面2选1
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile
|