M1 MacBook Pro安装Homebrew时遇到的问题

1,489 阅读1分钟

我的电脑系统是M1芯片的macOS Monterey,12.1。

安装Homebrew时,前面遇到了几次问题,多是由于要访问GitHub导致的墙的问题,失败了几次。

墙的问题解决后,在Homebrew安装不完整的条件下,再次安装brew时,遇到如下情况:

 ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"            
==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R liangtianyi:admin /opt/homebrew
==> Downloading and installing Homebrew...
HEAD is now at 26941f0bf Merge pull request #12719 from Homebrew/dependabot/bundler/Library/Homebrew/sorbet-0.5.9519
(注意这里↓↓↓↓↓↓)
error: Not a valid ref: refs/remotes/origin/master
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>...]'
fatal: Could not resolve HEAD to a revision
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

虽然提示安装成功,但是这种情况会导致brew update的时候报错,所以还是需要解决的。

这里遇到的问题本以为是安装脚本本身的问题,但是怀疑前面装了几次中途失败的情况,决定清理干净brew后重新安装。

如何把brew删除干净,建议按照以下这段话删除:

(this is one of `/usr/local``/opt/homebrew`, or `/home/linuxbrew/.linuxbrew` depending on your machine)

有的文件夹不存在,可以忽略,然后重新执行安装命令即可。