Mac Homebrew离线安装需提前导出匹配架构与macOS版本的bottle文件,重命名为curl--8.10.1.mojave.bottle.tar.gz格式,放入$(brew --cache)/homebrew-core/目录,并用brew install --force-bottle --no-quarantine命令安装。

Mac Homebrew在没有网络时无法自动下载formula源码或二进制包,但如果你已提前在有网机器上导出过瓶装包(.tar.gz),就能跳过联网步骤完成安装。这要求你手头已有对应架构(Intel 或 Apple Silicon)和 macOS 版本的 bottle 文件,并确认其完整性与依赖兼容性。
确认本地 bottle 文件是否可用
进入存放 bottle 的目录,执行:ls -l *.tar.gz。必须看到形如 curl-8.10.1.mojave.bottle.tar.gz 或 curl-8.10.1.arm64_monterey.bottle.tar.gz 的文件——其中包含系统代号(mojave、ventura、sonoma、sequoia)和架构(x86_64 或 arm64)。若只有 curl-8.10.1.tar.gz(无 .bottle)则不是 bottle,不能直接用 brew install 安装。
运行 brew tap | grep homebrew-core,确保输出中含 homebrew/core。若为空,说明 core tap 未加载,离线安装会失败——【必须先在有网环境执行 brew tap homebrew/core】,否则本地 bottle 无法被识别为合法 formula。
将 bottle 文件注入 Homebrew 本地缓存
执行:brew fetch --force --bottle-tag=$(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/curl.rb —— 这条命令无效,因为 brew fetch 强制联网。正确做法是手动复制:
把 bottle 文件重命名为严格匹配 Homebrew 期望的格式:例如你要装 curl,先运行 brew info curl 查看当前公式路径,再根据输出中的 bottle URL 推导命名。典型格式为:curl--8.10.1.mojave.bottle.tar.gz(双短横分隔名与版本)。名字错一位、少一个点、系统代号不匹配,brew 都会拒绝使用。
将重命名后的文件放入:$(brew --cache)/homebrew-core/ 目录。该目录默认为 /opt/homebrew/cache/homebrew-core(Apple Silicon)或 /usr/local/Homebrew/cache/homebrew-core(Intel)。若该路径不存在,先创建:mkdir -p $(brew --cache)/homebrew-core。
强制从本地缓存安装 bottle
第一步:关闭 Homebrew 的远程检查机制。编辑 brew 源码中的校验逻辑会破坏签名,不可行;更安全的做法是临时欺骗 brew 认为 bottle 已“下载完成”。执行:touch $(brew --cache)/homebrew-core/curl--8.10.1.mojave.bottle.tar.gz —— 这只是占位,真正起作用的是下一步。
第二步:用 --force-bottle 和 --no-quarantine 绕过网络验证与 Gatekeeper 检查:brew install --force-bottle --no-quarantine curl。此时 brew 会查找本地 cache 中匹配的 .bottle.tar.gz 并解压安装。
若报错 Error: No available bottle for curl,说明命名或路径不匹配。请回到上一步,用 brew cat curl 查看 formula 中 bottle do 块内声明的 exact tag,例如 sha256 "abc123" => :mojave,然后确保你的文件名含 mojave 且扩展名是 .bottle.tar.gz。
安装成功后,执行 brew list curl 确认已注册;运行 curl --version 验证可执行文件正常工作。

















