tar: Error opening archive: Failed to open when upgrade using brew

When I am using this command to upgrade my macOS big sur:

brew upgrade

shows some package could not be opened log:

==> Installing dependencies for sphinx-doc: gdbm, sqlite and [email protected]
==> Installing sphinx-doc dependency: gdbm
==> Pouring gdbm-1.20.big_sur.bottle.tar.gz
tar: Error opening archive: Failed to open '/Users/dolphin/Library/Caches/Homebrew/downloads/1ba06466fa01d44d117c266b9618127cf798782c736869d87ccfc0bc7cd25f12--gdbm-1.20.big_sur.bottle.tar.gz'
Error: Failure while executing; `tar --extract --no-same-owner --file /Users/dolphin/Library/Caches/Homebrew/downloads/1ba06466fa01d44d117c266b9618127cf798782c736869d87ccfc0bc7cd25f12--gdbm-1.20.big_sur.bottle.tar.gz --directory /private/tmp/d20210715-82868-1ez91q9` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/dolphin/Library/Caches/Homebrew/downloads/1ba06466fa01d44d117c266b9618127cf798782c736869d87ccfc0bc7cd25f12--gdbm-1.20.big_sur.bottle.tar.gz'

(base)

I am using this command to check the file:

~/Library/Caches/Homebrew/downloads ⌚ 16:53:27
$ ls 1ba06466fa01d44d117c266b9618127cf798782c736869d87ccfc0bc7cd25f12--gdbm-1.20.big_sur.bottle.tar.gz   ‹ruby-2.7.2›
ls: 1ba06466fa01d44d117c266b9618127cf798782c736869d87ccfc0bc7cd25f12--gdbm-1.20.big_sur.bottle.tar.gz: No such file or directory
(base)

could not found the file, what should I do to fix the problem? I have already tried run:

brew cleanup

still not work.


Solution 1:

If you use a mirror of Homebrew, do not use it anymore, or try other mirror.

In a temp way, bypass the mirror: export HOMEBREW_BOTTLE_DOMAIN=''

Try another mirror export HOMEBREW_BOTTLE_DOMAIN=https://another.mirrors.domain/homebrew-bottles

Or you can put it in your ~/.zprofile to make it effective in a long way:

echo 'export HOMEBREW_BOTTLE_DOMAIN=""' >> ~/.zprofile

Because:

Homebrew's binary packages were migrated to GitHub Packages: https://github.com/orgs/Homebrew/package

On May 1, 2021, the sunset will impact all existing Bintray users. Bintray users will be blocked and will no longer be able to use the Bintray service.

Refer to:

  1. Bintray shuts down #691
  2. Into the Sunset on May 1st: Bintray, GoCenter, and ChartCenter