FAQ

解决 formulae.brew.sh/api/xxx.json 失败问题

执行下面内容后,重新执行安装脚本:

echo 'export HOMEBREW_API_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/api #brew.idayer.com' >> ~/.zprofile
source ~/.zprofile

加速工具

免责声明:列出以下内容仅仅是提供应急所需,不对服务的稳定性提供保证。

终端设置代理

在你的代理软件中找到http端口号,然后把下面脚本中的1080替换成你找到的端口号,然后在终端执行。

// 给终端设置代理
export http_proxy=http://127.0.0.1:1080;export https_proxy=$http_proxy;export all_proxy=$http_proxy
// 取消代理设置
unset http_proxy;unset https_proxy;unset all_proxy

验证是否生效

在终端执行以下脚本可以验证:

curl https://www.google.com -I

如果返回结果第一行包含HTTP/1.1 200 OK则说明已生效。

取消 git 代理

当遇到包含"Unsupported proxy syntax in"提示的问题是,和可能是设置了git代理,同时代理无法访问。

这个时候可以考虑重新打开代理,另外的方案就是取消代理方式:

git config --global --unset http.proxy
git config --global --unset https.proxy

如何删除 Homebrew

遇到解决不了的问题,先删除homebrew目录再重新运行脚本安装。

删除可以通过脚本或者在文件夹中删除(mac):

// m1,m2
sudo rm -rf /opt/homebrew
// intel
sudo rm -rf /usr/local/Homebrew

使用rm -rf命令是比较危险的行为,请不要随意修改最后的目录名。

macOS

  • Intel 上安装目录: /usr/local/Homebrew/
  • m1 arm 上安装目录: /opt/homebrew

另外在终端可以执行open /usr/local/Homebrew/open /opt/homebrew,打开文件夹通过界面删除。

Linux

安装目录在/home/linuxbrew

手动设置 homebrew-core

cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-core.git

手动设置 homebrew-core

cd "$(brew --repo)/Library/Taps/"
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git

安装时 formulae 找不到

如果遇到下面的提示。

==> Searching for similarly named formulae...
Error: No similarly named formulae found.
Error: No available formula or cask with the name "nasm".
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

尝试执行以下命令:

rm -rf $(brew --repo homebrew/core)
brew tap homebrew/core

如果还不行,请删除homebrew目录,再重新安装。

certificate has expired

近期很多人反馈安装brew遇到下面的错误:

fatal: unable to access 'https://mirrors.ustc.edu.cn/brew.git/': SSL certificate problem: certificate has expired

目前临时的解决方案如下:

git config --global http.sslVerify false

M1 芯片 Mac 如何安装

Homebrew已支持在arm上安装,但是一些软件兼容性还有待更新,官方查阅地址可看 说明

你可以考虑安装x86版本保持兼容性。

无论安装哪个版本,强烈建议先参考文档:M1 芯片 Mac 上 Homebrew 安装

大部分问题都是资源不稳定导致的,如果可以的话尽量通过代理加速。

代理使用可以参考以下文章:

brew install xxx 404 的问题

原因是bottles镜像地址更新了,需要在 ~/.zprofile~/.bash_profile 文件更新镜像地址。

至于选择哪个文件来操作,请按照 判断终端

  1. 找到HOMEBREW_BOTTLE_DOMAIN配置,一般是这样的形式:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
  1. 然后使用 镜像助手 获取替换的地址,复制 HOMEBREW_BOTTLE_DOMAIN 后面链接地址。

比如中科大镜像就是这个了:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles
  1. 更新环境变量,以 ~/.zprofile 为例,更新内容后执行:
source ~/.zprofile

判断终端

可以先通过以下方式获取:

执行命令echo $SHELL,根据结果判断:

  • /bin/zsh => zsh => .zprofile
  • /bin/bash => bash => .bash_profile

注意:文章内如有再次提及编辑.zprofile,均按此方法判断具体操作的文件。

fatal: unable to access xxx

HEAD is now at 028e733e7 Merge pull request #10260 from reitermarkus/audit-livecheck
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': transfer closed with outstanding read data remaining
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

解决方案:

设置镜像无效,安装还是很慢

这里说的安装很慢主要是指brew本身安装速度慢(镜像地址没有设置成功)。

可以执行命令echo $SHELL,先查看终端类型。

  • bash: /bin/bash
  • zsh: /bin/zsh

然后根据终端类型设置镜像,参考 判断终端

command not found: brew

一般是环境变量无效,请使用echo $SHELL确认终端类型,参考前一段落。

m1芯片Mac电脑需要手动设置环境变量:

zsh

echo 'eval "$(/opt/homebrew/bin/brew shellenv)" #brew.idayer.com' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

bash

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

m1的话,可以尝试手动加入环境变量:

zsh

echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)" #brew.idayer.com' >> ~/.zprofile
eval "$(/usr/local/Homebrew/bin/brew shellenv)"

bash

echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)" brew.idayer.com' >> ~/.bash_profile
eval "$(/usr/local/Homebrew/bin/brew shellenv)"

SHA256 mismatch

Error: An exception occurred within a child process:
ChecksumMismatchError: SHA256 mismatch
Expected: 01059532335fefc5e0e7a23cc79eeb1dc6fea477606981b89f259aa0e0f9abc1
Actual: 641ba394c891cee16dfa45873906edab12edfc9befaa121649bb18e7b7d574bf
Archive: /Users/XXX/Library/Caches/Homebrew/downloads/1124b500fc261f6d9be6193eca8c120f4dfb7ecd3470ac7d8edc1d04ecc5b345--jdk13u-jdk-13.0.2+8.tar.bz2
To retry an incomplete download, remove the file above.

遇到该问题时请尝试该方案:https://blog.csdn.net/lemostic/article/details/107101219

homebrew-bundle错误

fatal: unable to access 'https://github.com/homebrew/homebrew-bundle/': Recv failure: Operation timed out
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-bundle failed!
Failed during: /usr/local/bin/brew update --force --quiet

这个错误是因为bundle工具默认内置的GitHub资源,这很容易导致出现方式失败的情况,请直接执行以下命令:

git -C "$(brew --repo)/Library/Taps/homebrew/homebrew-bundle" remote set-url origin https://gitee.com/imirror/homebrew-bundle.git

如何判断终端类型

在终端执行命令echo $SHELL,根据显示的结果判断:

  • /bin/bash => bash => .bash_profile
  • /bin/zsh => zsh => .zprofile

Xcode Command Line 安装问题

错误如下:

xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

这是因为CommandLineTools未安装的原因,可以通过命令安装:

xcode-select --install

如果提示"不能下载该软件,因为网络出现问题",可以在官网下载安装。

  1. 打开 https://developer.apple.com/download/more/
  2. 搜索 Command Line

因为这里罗列的所有的版本,所以我们还需要确定支持的版本,我们这样操作:

  1. 确定当前系统版本

  2. 打开App Store搜索XcodeWX20210218-184737@2x.png

  3. 点击"版本历史记录"找到支持你的系统版本的Xcode版本号WX20210218-184755@2x.png

举例子我的电脑是Big Sur 11.2,在版本记录里看到12.4就是Xcode对应的版本号,然后我们找到"Command Line Tools for Xcode 12.4"下载。

raw.githubusercontent.com 无法访问

这是典型的GitHub不稳定的表现,你可以通过设置hosts缓解该问题。

参考 GitHub 加速教程

需要帮助?
建议先查阅 FAQ
扫码回复"brew"进群