Homebrew安装node依赖失败 找不到libnghttp2文件如何解决
Homebrew安装node报libnghttp2缓存文件不存在解决方法
报错现象
执行brew install node时,程序自动拉取node依赖:libnghttp2、libuv、ca-certificates、openssl@1.1,走到libnghttp2安装步骤、解压对应版本预编译bottle包时抛出错误,提示指定缓存路径下安装包不存在,完整运行日志:
==> Installing dependencies for node: libnghttp2, libuv, ca-certificates and openssl@1.1 ==> Installing node dependency: libnghttp2 ==> Pouring libnghttp2-1.48.0.arm64_monterey.bottle.tar.gz Error: No such file or directory @ rb_sysopen - /Users/lky/Library/Caches/Homebrew/downloads/01903ff762254112edcbfc63f384af2c616deb9c819dbc96f092d5078049404e--libnghttp2-1.48.0.arm64_monterey.bottle.tar.gz
触发原因
Homebrew下载bottle安装包过程中出现网络中断、缓存写入失败,或之前的清理操作误删了未完成下载的缓存文件,导致安装阶段读取目标路径文件时找不到对应资源。
修复步骤
按顺序执行以下命令操作:
- 清理libnghttp2对应的旧缓存记录:
brew cleanup libnghttp2 - 删除缓存目录下可能残留的损坏不完整文件:
rm -rf /Users/lky/Library/Caches/Homebrew/downloads/*libnghttp2-1.48.0.arm64_monterey.bottle.tar.gz*
路径中
lky为日志里的用户名,实际操作时替换为你自己设备的Mac用户名即可
- 同步Homebrew本地包索引,避免版本不匹配导致的拉取异常:
brew update - 重新执行node安装命令:
brew install node
兜底方案
如果以上步骤执行后仍然报相同错误,可以跳过预编译bottle包,直接从源码编译安装libnghttp2后再安装node,执行命令:brew install --build-from-source libnghttp2 && brew install node
内容的提问来源于stack exchange,提问作者罗楷源
相关产品推荐
相关产品推荐

