
字数:2384 字
预计阅读时间:20 分钟
撰写时间:2026年01月23日
统一管理软件包。
安装 PowerShell7 的前置依赖。
参考链接,这里只留下 macOS 的安装方法
https://www.trae.cn/article/660492802
选择国内清华源镜像会自动将安装后的homebrew配置修改为清华源对应的
清华镜像(官方脚本 + 环境变量)
# 修改变量临时指向清华源,仅在下载时做加速用
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
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"
# 安装脚本本体就是从 raw.githubusercontent.com 拉的,若无法直连GitHub,仍然可能导致安装失败
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
分别是以下这两个变量:
HOMEBREW_API_DOMAIN
HOMEBREW_BOTTLE_DOMAIN
在国内网络环境下通常强烈建议配置,否则用户会经常遇到:下载瓶子(bottles)慢 / 超时(因为默认会碰 GHCR/GitHub 相关链路),进而影响程序的安装,会引发疑虑:清华源镜像是否配置成功🏅。
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofile
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
Apple Silicon(M Serials)
为什么动态加载环境变量?
答:Homebrew 的安装前缀不是固定的,Intel CPU和 M系列CPU 各有不同
兼容不同 shell + 不同现场环境
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
charles@MacBook-Pro ~ % brew config
HOMEBREW_VERSION: 5.0.11
ORIGIN: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
HEAD: a36eea6fe705eef966f0acd609e471c9b7541a6b
Last commit: 4 days ago
Branch: stable
Core tap JSON: 21 Jan 19:32 UTC
Core cask tap JSON: 21 Jan 19:32 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DOWNLOAD_CONCURRENCY: 20
HOMEBREW_FORBID_PACKAGES_FROM_PATHS: set
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 3.4.8 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.8/bin/ruby
CPU: deca-core 64-bit dunno
Clang: 17.0.0 build 1700
Git: 2.50.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 26.2-arm64
CLT: 26.2.0.0.1.1764812424
检查 ORIGIN 字段的值,是否为镜像站地址
ORIGIN: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git