准备
ARM版Homebrew需要安装在/opt/homebrew路径下,早期的时候需要手动创建目录执行命令,目前使用最新脚本不需要手动操作。
/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,所以对应命令:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
安装 X86 版 Homebrew
因为目前很多软件包没有支持ARM架构,我们也可以考虑使用x86版的Homebrew。
在命令前面添加arch -x86_64,就可以按X86模式执行该命令,比如:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
source ~/.zprofile
设置镜像
注意:本文中的安装脚本会设置中科大源镜像,如果你也想设置cask和bottles的镜像,请按下面注释部分选择执行代码。
更详细的教程可以参考前面「mac下镜像飞速安装Homebrew教程」
执行时根据实际情况修改"$(brew --repo)"代码中的brew。
意思是如果你只是使用一个版本Homebrew,直接执行命令即可,如果你想多个版本共存或者使用了别名,就把brew关键字替换为别名名称,如前面的abrew、ibrew。
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
常用命令
- brew -v 查询HomeBrew版本
- brew -h brew帮助
- brew update 更新Homebrew
- brew install <pkg_name> 安装任意软件
- brew uninstall <pkg_name> 卸载任意软件
- brew search <pkg_name> 查询任意包
- brew list 列出已安装的软件列表
- brew list git 列出已安装软件git的文件目录
- brew info <pkg_name> 查看任意包内容信息
- brew upgrade <pkg_name> 更新任意包
- brew cleanup <pkg_name> 删除具体旧软件
- brew cleanup 删除所有旧软件
- brew outdated 已安装的包是否需要更新
- brew deps 已安装的包是否需要更新
HomeBrew安装node.js
brew install node
node -v
可能出现的报错
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)
解决方法
eval "$(/opt/homebrew/bin/brew shellenv)"