01-国内环境安装Homebrew

nobility 发布于 12 天前 03-Homebrew 41 次阅读


国内环境安装 Homebrew

脚本安装

我在 Gitee 上发现了 HomebrewCN 项目,支持国内环境自动安装 Homebrew 包管理工具(支持选择镜像源),该脚本会自动检测网络环境,提供清华、中科大等镜像源选项,完成安装后无需额外配置。

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

也可以选择安装精简版:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed

手动安装

这里以清华镜像源为例。

首先,安装前置依赖:

# 安装Xcode命令行工具
xcode-select --install

设置环境变量:

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"

克隆安装脚本并执行:

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

验证安装:

brew --version  # 显示版本号即成功

配置 Homebrew 软件源

建议配置国内镜像源加速后续使用,这里以中科大学镜像为例:

# 替换核心仓库
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 配置 bottle 源
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

查看 Homebrew 软件源

查看已添加的源

brew tap

会列出所有已连接的公式仓库(tap),例如,默认的 homebrew/corehomebrew/cask。其他任何第三方或自定义的源也会在这里显示。

检查源是否被修改

每个 tap 的源地址可通过 Git 命令验证:

cd $(brew --repository)/Library/Taps/<tap路径>
git remote -v

例如,检查核心仓库:

cd $(brew --repository)/Library/Taps/homebrew/homebrew-core
git remote -v

默认官方源的 URL 应为 https://github.com/Homebrew/homebrew-core,如果显示其他地址,则说明源被修改过。

检查具体公式(如 repo)的来源,可以通过如下命令查看公式的仓库路径和源码地址:

brew info repo

📝 注意:

  • 第三方 tap(比如 petere/postgresql)属于用户主动添加的扩展源,不算作异常修改。
加油啊!即便没有转生到异世界,也要拿出真本事!!!\(`Δ’)/
最后更新于 2026-03-01