修复homebrew安装软件404问题

作为追新族,基本上我所有设备上的系统、软件,都会在第一时间更新到最新。因此我经常运行各种update命令,包括brew upgrade,但今天,发现和往常不太一样。

在更新软件时,终端中有不少黄字提示404警告,并且最后的结果也出错了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#=#=-#  #
curl: (22) The requested URL returned error: 404 Not Found
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/blobs/sha256:83547fba540a38c30705a59a2e746952c68857212e823c6ee97c186e088f75cd
==> Downloading from https://pkg-containers-az.githubusercontent.com/ghcr1/blobs/sha256:83547fba540a38c30705a59a2e746952c68857212e823c6ee97c186e088f75cd?se=2021-04-22T06%3A55%3
######################################################################## 100.0%
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/ruby-3.0.1.big_sur.bottle.tar.gz
==> Downloading from https://homebrew.bintray.com/ruby-3.0.1.big_sur.bottle.tar.gz
#=#=-# #
curl: (22) The requested URL returned error: 404 Not Found
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:00daa93e4b30d3bbeac5089c1c34355315774e0d9fd1d9588402b2e755089c53
==> Downloading from https://pkg-containers-az.githubusercontent.com/ghcr1/blobs/sha256:00daa93e4b30d3bbeac5089c1c34355315774e0d9fd1d9588402b2e755089c53?se=2021-04-22T06%3A55%3
######################################################################## 100.0%
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/vim-8.2.2775.big_sur.bottle.tar.gz
==> Downloading from https://homebrew.bintray.com/vim-8.2.2775.big_sur.bottle.tar.gz
#=#=-# #
curl: (22) The requested URL returned error: 404 Not Found
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/vim/manifests/8.2.2775
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/vim/blobs/sha256:2d48b73b8157241aef912e1fdc7e587837b60e4898f69d597b1f4182a520afe2
==> Downloading from https://pkg-containers-az.githubusercontent.com/ghcr1/blobs/sha256:2d48b73b8157241aef912e1fdc7e587837b60e4898f69d597b1f4182a520afe2?se=2021-04-22T06%3A55%3
######################################################################## 100.0%
==> Installing dependencies for vim: gettext, lua, ncurses, [email protected], berkeley-db, gdbm, perl, mpdecimal, readline, sqlite, xz, [email protected], libyaml and ruby
==> Installing vim dependency: gettext
==> Pouring gettext-0.21.big_sur.bottle.tar.gz
tar: Error opening archive: Failed to open '/Users/username/Library/Caches/Homebrew/downloads/8835c3d1869eedf98376360b02e32e1ec1fcb790687cfa164713bea02c45e577--gettext-0.21.big_sur.bottle.tar.gz'
Error: Failure while executing; `tar --extract --no-same-owner --file /Users/username/Library/Caches/Homebrew/downloads/8835c3d1869eedf98376360b02e32e1ec1fcb790687cfa164713bea02c45e577--gettext-0.21.big_sur.bottle.tar.gz --directory /var/folders/7h/dkrm4zdd6bv315h44vqhx5pr0000gn/T/d20210422-22363-1sups7j` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/username/Library/Caches/Homebrew/downloads/8835c3d1869eedf98376360b02e32e1ec1fcb790687cfa164713bea02c45e577--gettext-0.21.big_sur.bottle.tar.gz'

不会吧?一个用户基数这么大的服务,居然会出现这么多404 :mrgreen: ?去GitHub一查,好嘛,原来是bintray要关闭了,具体看这里,应该是截止到某个时间点,之后的包就没再往bintray传了,也就是404了。

其实Homebrew社区对这个问题早就做了准备的,新版的homebrew程序已经去除了bintray相关,使用ghcr.io服务了,所以只要正常使用,正常先update,再upgrade,是可以完美过渡,用户是无感的。

至于我为啥不行,是因为我用了清华大学的镜像,目前清华大学的镜像中依然是指向到bintray的,所以也跟着404了。所以要解决问题,那就是去掉清华大学的镜像设置就好了。具体的环境变量是$HOMEBREW_BOTTLE_DOMAIN。使用export HOMEBREW_BOTTLE_DOMAIN=’’命令就可以去除。上面是临时修改,如果想永久修改,则需要去更新profile文件,zsh是/.zprofile文件,bash要修改/.bash_profile文件。

修改完后,再进行安装,就一切正常了。

我后来又去清华大学的GitHub上看了,已经有人反馈这个问题了,同时发现 https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/ 目录下并没有直接列出各种包,反而多了一个bottles目录,想必清华大学已经是在处理这个问题,开始同步了吧。只是这个镜像有2.5T大,要完全同步完,真不知道猴年马月了。