苹果电脑使用brew时,出现Warning: formula.jws.json: update failed, falling back to cached version.Error: Cannot download non-corrupt https://formulae.brew.sh/api/formula.jws.json!
这个错误表明 Homebrew 在尝试更新自身时遇到了网络问题,Homebrew默认从官方的JSON API镜像下载,而这个镜像在一些地区可能访问速度比较慢或者不稳定。所以我们需要更换一个可靠的JSON API镜像来解决这个问题。
# 替换 Homebrew 源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换 Homebrew-core 源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替换 Homebrew-cask 源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 设置 API 镜像
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.zshrc
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.zshrc
source ~/.zshrc
执行完以上操作以后,现在你可以继续执行你原来的操作啦~
更新生效
如何更新生效,可以执行:
brew update
后续的话呢,你也可以每段时间不定期的更新一下的 homebrew ,以便获得最好的最新的体验和功能。
# 每月执行一次
brew update
brew upgrade
brew cleanup