执行brew upgrade时出现curl: (22) 404错误求助
执行brew upgrade时出现以下404错误,但brew list等其他命令正常:
==> Downloading https://formulae.brew.sh/api/cask.jws.json
curl: (22) The requested URL returned error: 404
Error: Failure while executing;
/usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --user-agent Homebrew/4.0.13\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 12.6.2\)\ curl/7.79.1 --header Accept-Language:\ en --fail --progress-bar --location --remote-time --output /Users/username/Library/Caches/Homebrew/api/cask.jws.json --compressed --speed-limit 100 --speed-time 5 --progress-bar https://formulae.brew.sh/api/cask.jws.jsonexited with 22. Here's the output:
curl: (22) The requested URL returned error: 404
可以尝试以下步骤解决:
清理Homebrew缓存
缓存的旧API文件可能导致错误,执行命令清理:brew cleanup -s rm -rf ~/Library/Caches/Homebrew/api更新Homebrew核心
先更新brew本身,确保使用最新的API路径:brew update如果
brew update失败,强制重置brew的git仓库:cd "$(brew --repo)" git fetch --prune git reset --hard origin/master brew update-reset检查网络连接
测试能否正常访问目标API地址:curl -I https://formulae.brew.sh/api/cask.jws.json如果仍返回404,尝试切换网络(如手机热点),或检查本地代理、防火墙是否拦截了请求。
手动修复API路径(极端情况)
若上述方法无效,可能是旧版本brew使用了废弃的API路径。编辑brew的API配置文件(路径通常为/usr/local/Homebrew/Library/Homebrew/api.rb),将涉及cask.jws.json的地址替换为最新路径,或直接升级到最新版brew。
内容的提问来源于stack exchange,提问作者willwrighteng

