macOS Homebrew错误汇编(踩坑指南)

事情的起因是升级了macOS,然后homebrew就各种报错。

Error: Can't create update lock in /usr/local/var/homebrew/locks!
Fix permissions by running:
sudo chown -R $(whoami) /usr/local/var/homebrew
Traceback (most recent call last):
11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `<main>'
10: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `require_relative'
9: from /usr/local/Homebrew/Library/Homebrew/global.rb:80:in `<top (required)>'
8: from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
7: from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
6: from /usr/local/Homebrew/Library/Homebrew/os.rb:7:in `<top (required)>'
5: from /usr/local/Homebrew/Library/Homebrew/os.rb:43:in `<module:OS>'
4: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:60:in `prerelease?'
3: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:28:in `version'
2: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `from_symbol'
1: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `fetch'
/usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:33:in `block in from_symbol': unknown or unsupported macOS version: :dunno (MacOSVersionError)

升级

重新拉仓库

事实证明这个重新拉库的方法没什么卵用 …

➜  ~ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
fatal: 对于一个完整的仓库,参数 --unshallow 没有意义

brew update-reset

➜  ~ brew update-reset
==> Fetching /usr/local/Homebrew...
error: cannot open .git/FETCH_HEAD: Permission denied
error: Unable to create '/usr/local/Homebrew/.git/refs/remotes/origin/HEAD.lock': Permission denied
error: Could not setup refs/remotes/origin/HEAD

==> Resetting /usr/local/Homebrew...
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref
fatal: 'origin/HEAD' is not a commit and a branch '' cannot be created from it

==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
error: cannot open .git/FETCH_HEAD: Permission denied
error: Unable to create '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/refs/remotes/origin/HEAD.lock': Permission denied
error: Could not setup refs/remotes/origin/HEAD

==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
fatal: Unable to create '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/index.lock': Permission denied

==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
error: cannot open .git/FETCH_HEAD: Permission denied
error: Unable to create '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/refs/remotes/origin/HEAD.lock': Permission denied
error: Could not setup refs/remotes/origin/HEAD

==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
fatal: Unable to create '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/index.lock': Permission denied

我一看这是权限不够,加权限吧。

➜  ~ sudo brew update-reset
Password:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

这尼玛又告诉我sudo root危险?

重装

官网有命令

去官网,https://brew.sh/,有重装命令。

➜  ~ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/etc/bash_completion.d
/usr/local/share/aclocal
/usr/local/share/info
/usr/local/share/locale
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
/usr/local/share/man/man8
/usr/local/bin/brew
==> The following existing directories will have their owner set to sunyg:
/usr/local/etc/bash_completion.d
/usr/local/share/aclocal
/usr/local/share/info
/usr/local/share/locale
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
/usr/local/share/man/man8
/usr/local/bin/brew
==> The Xcode Command Line Tools will be installed.

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/etc/bash_completion.d /usr/local/share/aclocal /usr/local/share/info /usr/local/share/locale /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/bin/brew
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/etc/bash_completion.d /usr/local/share/aclocal /usr/local/share/info /usr/local/share/locale /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/bin/brew
==> /usr/bin/sudo /usr/sbin/chown sunyg /usr/local/etc/bash_completion.d /usr/local/share/aclocal /usr/local/share/info /usr/local/share/locale /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/bin/brew
==> /usr/bin/sudo /usr/sbin/chown -R sunyg:admin /usr/local/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Users/sunyg/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/sunyg/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown -R sunyg /Users/sunyg/Library/Caches/Homebrew
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools for Xcode-15.1
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-15.1
Software Update Tool

Finding available software

Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
Password:
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Downloading and installing Homebrew...
remote: Enumerating objects: 79259, done.
remote: Counting objects: 100% (35813/35813), done.
remote: Compressing objects: 100% (1028/1028), done.
error: 3736 bytes of body are still expected MiB | 411.00 KiB/s
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
Failed during: /usr/bin/git fetch --force origin

这尼玛网络又中断了

再来 …

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

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R sunyg:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 79259, done.
remote: Counting objects: 100% (35813/35813), done.
remote: Compressing objects: 100% (1028/1028), done.
remote: Total 79259 (delta 34854), reused 35484 (delta 34682), pack-reused 43446
Receiving objects: 100% (79259/79259), 27.60 MiB | 838.00 KiB/s, done.
Resolving deltas: 100% (54551/54551), completed with 1431 local objects.
From https://github.com/Homebrew/brew
53d840c96..044d06d10 master -> origin/master
* [new tag] 3.0.10 -> 3.0.10
* [new tag] 3.0.11 -> 3.0.11
* [new tag] 3.0.2 -> 3.0.2
* [new tag] 3.0.3 -> 3.0.3
* [new tag] 3.0.4 -> 3.0.4
* [new tag] 3.0.5 -> 3.0.5
* [new tag] 3.0.6 -> 3.0.6
* [new tag] 3.0.7 -> 3.0.7
* [new tag] 3.0.8 -> 3.0.8
* [new tag] 3.0.9 -> 3.0.9
* [new tag] 3.1.0 -> 3.1.0
* [new tag] 3.1.1 -> 3.1.1
* [new tag] 3.1.10 -> 3.1.10
* [new tag] 3.1.11 -> 3.1.11
* [new tag] 3.1.12 -> 3.1.12
* [new tag] 3.1.2 -> 3.1.2
* [new tag] 3.1.3 -> 3.1.3
* [new tag] 3.1.4 -> 3.1.4
* [new tag] 3.1.5 -> 3.1.5
* [new tag] 3.1.6 -> 3.1.6
* [new tag] 3.1.7 -> 3.1.7
* [new tag] 3.1.8 -> 3.1.8
* [new tag] 3.1.9 -> 3.1.9
* [new tag] 3.2.0 -> 3.2.0
* [new tag] 3.2.1 -> 3.2.1
* [new tag] 3.2.10 -> 3.2.10
* [new tag] 3.2.11 -> 3.2.11
* [new tag] 3.2.12 -> 3.2.12
* [new tag] 3.2.13 -> 3.2.13
* [new tag] 3.2.14 -> 3.2.14
* [new tag] 3.2.15 -> 3.2.15
* [new tag] 3.2.16 -> 3.2.16
* [new tag] 3.2.17 -> 3.2.17
* [new tag] 3.2.2 -> 3.2.2
* [new tag] 3.2.3 -> 3.2.3
* [new tag] 3.2.4 -> 3.2.4
* [new tag] 3.2.5 -> 3.2.5
* [new tag] 3.2.6 -> 3.2.6
* [new tag] 3.2.7 -> 3.2.7
* [new tag] 3.2.8 -> 3.2.8
* [new tag] 3.2.9 -> 3.2.9
* [new tag] 3.3.0 -> 3.3.0
* [new tag] 3.3.1 -> 3.3.1
* [new tag] 3.3.10 -> 3.3.10
* [new tag] 3.3.11 -> 3.3.11
* [new tag] 3.3.12 -> 3.3.12
* [new tag] 3.3.13 -> 3.3.13
* [new tag] 3.3.14 -> 3.3.14
* [new tag] 3.3.15 -> 3.3.15
* [new tag] 3.3.16 -> 3.3.16
* [new tag] 3.3.2 -> 3.3.2
* [new tag] 3.3.3 -> 3.3.3
* [new tag] 3.3.4 -> 3.3.4
* [new tag] 3.3.5 -> 3.3.5
* [new tag] 3.3.6 -> 3.3.6
* [new tag] 3.3.7 -> 3.3.7
* [new tag] 3.3.8 -> 3.3.8
* [new tag] 3.3.9 -> 3.3.9
* [new tag] 3.4.0 -> 3.4.0
* [new tag] 3.4.1 -> 3.4.1
* [new tag] 3.4.10 -> 3.4.10
* [new tag] 3.4.11 -> 3.4.11
* [new tag] 3.4.2 -> 3.4.2
* [new tag] 3.4.3 -> 3.4.3
* [new tag] 3.4.4 -> 3.4.4
* [new tag] 3.4.5 -> 3.4.5
* [new tag] 3.4.6 -> 3.4.6
* [new tag] 3.4.7 -> 3.4.7
* [new tag] 3.4.8 -> 3.4.8
* [new tag] 3.4.9 -> 3.4.9
* [new tag] 3.5.0 -> 3.5.0
* [new tag] 3.5.1 -> 3.5.1
* [new tag] 3.5.10 -> 3.5.10
* [new tag] 3.5.2 -> 3.5.2
* [new tag] 3.5.3 -> 3.5.3
* [new tag] 3.5.4 -> 3.5.4
* [new tag] 3.5.5 -> 3.5.5
* [new tag] 3.5.6 -> 3.5.6
* [new tag] 3.5.7 -> 3.5.7
* [new tag] 3.5.8 -> 3.5.8
* [new tag] 3.5.9 -> 3.5.9
* [new tag] 3.6.0 -> 3.6.0
* [new tag] 3.6.1 -> 3.6.1
* [new tag] 3.6.10 -> 3.6.10
* [new tag] 3.6.11 -> 3.6.11
* [new tag] 3.6.12 -> 3.6.12
* [new tag] 3.6.13 -> 3.6.13
* [new tag] 3.6.14 -> 3.6.14
* [new tag] 3.6.15 -> 3.6.15
* [new tag] 3.6.16 -> 3.6.16
* [new tag] 3.6.17 -> 3.6.17
* [new tag] 3.6.18 -> 3.6.18
* [new tag] 3.6.19 -> 3.6.19
* [new tag] 3.6.2 -> 3.6.2
* [new tag] 3.6.20 -> 3.6.20
* [new tag] 3.6.21 -> 3.6.21
* [new tag] 3.6.3 -> 3.6.3
* [new tag] 3.6.4 -> 3.6.4
* [new tag] 3.6.5 -> 3.6.5
* [new tag] 3.6.6 -> 3.6.6
* [new tag] 3.6.7 -> 3.6.7
* [new tag] 3.6.8 -> 3.6.8
* [new tag] 3.6.9 -> 3.6.9
* [new tag] 4.0.0 -> 4.0.0
* [new tag] 4.0.1 -> 4.0.1
* [new tag] 4.0.10 -> 4.0.10
* [new tag] 4.0.11 -> 4.0.11
* [new tag] 4.0.12 -> 4.0.12
* [new tag] 4.0.13 -> 4.0.13
* [new tag] 4.0.14 -> 4.0.14
* [new tag] 4.0.15 -> 4.0.15
* [new tag] 4.0.16 -> 4.0.16
* [new tag] 4.0.17 -> 4.0.17
* [new tag] 4.0.18 -> 4.0.18
* [new tag] 4.0.19 -> 4.0.19
* [new tag] 4.0.2 -> 4.0.2
* [new tag] 4.0.20 -> 4.0.20
* [new tag] 4.0.21 -> 4.0.21
* [new tag] 4.0.22 -> 4.0.22
* [new tag] 4.0.23 -> 4.0.23
* [new tag] 4.0.24 -> 4.0.24
* [new tag] 4.0.25 -> 4.0.25
* [new tag] 4.0.26 -> 4.0.26
* [new tag] 4.0.27 -> 4.0.27
* [new tag] 4.0.28 -> 4.0.28
* [new tag] 4.0.3 -> 4.0.3
* [new tag] 4.0.4 -> 4.0.4
* [new tag] 4.0.5 -> 4.0.5
* [new tag] 4.0.6 -> 4.0.6
* [new tag] 4.0.7 -> 4.0.7
* [new tag] 4.0.8 -> 4.0.8
* [new tag] 4.0.9 -> 4.0.9
* [new tag] 4.1.0 -> 4.1.0
* [new tag] 4.1.1 -> 4.1.1
* [new tag] 4.1.10 -> 4.1.10
* [new tag] 4.1.11 -> 4.1.11
* [new tag] 4.1.12 -> 4.1.12
* [new tag] 4.1.13 -> 4.1.13
* [new tag] 4.1.14 -> 4.1.14
* [new tag] 4.1.15 -> 4.1.15
* [new tag] 4.1.16 -> 4.1.16
* [new tag] 4.1.17 -> 4.1.17
* [new tag] 4.1.18 -> 4.1.18
* [new tag] 4.1.19 -> 4.1.19
* [new tag] 4.1.2 -> 4.1.2
* [new tag] 4.1.20 -> 4.1.20
* [new tag] 4.1.21 -> 4.1.21
* [new tag] 4.1.22 -> 4.1.22
* [new tag] 4.1.23 -> 4.1.23
* [new tag] 4.1.24 -> 4.1.24
* [new tag] 4.1.25 -> 4.1.25
* [new tag] 4.1.3 -> 4.1.3
* [new tag] 4.1.4 -> 4.1.4
* [new tag] 4.1.5 -> 4.1.5
* [new tag] 4.1.6 -> 4.1.6
* [new tag] 4.1.7 -> 4.1.7
* [new tag] 4.1.8 -> 4.1.8
* [new tag] 4.2.0 -> 4.2.0
* [new tag] 4.2.1 -> 4.2.1
* [new tag] 4.2.2 -> 4.2.2
* [new tag] 4.2.3 -> 4.2.3
* [new tag] 4.2.4 -> 4.2.4
* [new tag] 4.2.5 -> 4.2.5
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (11/11), done.
remote: Total 18 (delta 11), reused 11 (delta 11), pack-reused 7
Unpacking objects: 100% (18/18), 3.38 KiB | 203.00 KiB/s, done.
From https://github.com/Homebrew/brew
* [new tag] 4.0.29 -> 4.0.29
* [new tag] 4.1.9 -> 4.1.9
HEAD is now at 044d06d10 Merge pull request #16524 from Homebrew/dependabot/bundler/Library/Homebrew/sorbet-runtime-and-sorbet-static-and-runtime-0.5.11216
Error: Can't create update lock in /usr/local/var/homebrew/locks!
Fix permissions by running:
sudo chown -R sunyg /usr/local/var/homebrew
Failed during: /usr/local/bin/brew update --force --quiet

这尼玛权限又关了

再来 …

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

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R sunyg:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 044d06d10 Merge pull request #16524 from Homebrew/dependabot/bundler/Library/Homebrew/sorbet-runtime-and-sorbet-static-and-runtime-0.5.11216
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:02180ca8b8295422ae84921bcf034b7ee8ce5575488bd5e6a37a192e53cd5d34
######################################################################### 100.0%
==> Pouring portable-ruby-3.1.4.el_capitan.bottle.tar.gz
Installing from the API is now the default behaviour!
You can save space and time by running:
brew untap homebrew/core
brew untap homebrew/cask
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/sunyg/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh

警告

  • Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

接着install就没事儿了 …

macOS Homebrew错误汇编(踩坑指南)

https://www.cctv3.net/static/20240124/macos-homebrew-tears.html

作者

江北饮马、江南折花

发布于

2024-01-24

更新于

2024-02-03

许可协议

评论