以下是在 Mac 上安装 Homebrew(brew)的几种方法:
官方命令安装
- 打开终端(Terminal),可以通过 Spotlight 搜索或在 “应用程序文件夹” 中找到 “实用工具” 文件夹,然后运行 “终端”。
- 在终端中输入以下命令并回车:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 安装过程中可能会要求输入管理员密码,输入后回车。等待安装完成,安装时长取决于计算机和网络速度。
- 安装完成后,在终端输入
brew --version
验证是否安装成功,若显示版本号则安装成功。
使用国内镜像安装
- 使用 Gitee 镜像:
- 打开终端,输入命令:
bash
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
- 按提示输入镜像序号,然后输入
Y
回车,等待 brew 安装完成。
- 打开终端,输入命令:
- 使用清华大学镜像3:
- 打开终端,输入命令:
bash
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
- 按提示输入管理员密码,等待下载和配置完成。
- 安装完成后,为避免后续更新和安装软件速度慢,建议切换到国内镜像,在终端依次输入以下命令:
bash
# 替换brew.git cd "$(brew --repo)" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git # 替换homebrew-core.git cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
如果提示
homebrew-core
目录不存在,说明首次安装后需先创建Taps
目录,可在终端依次输入以下命令:bash
mkdir -p "$(brew --repo)/Library/Taps/homebrew" cd "$(brew --repo)/Library/Taps/homebrew" git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git cd homebrew-core
- 打开终端,输入命令:
在安装 brew 之前,需要确保 macOS 系统已经更新到较新版本,并且已经安装了 Xcode Command Line Tools,可以通过在终端输入 xcode-select --install
进行安装或检查。