在 macOS 上使用 wget
下载文件时,如果你遇到如下致命错误:
dyld[70620]: Library not loaded: /usr/local/opt/libunistring/lib/libunistring.2.dylib
Reason: tried: … (no such file)
[1] 70620 abort wget https://developers.google.com/search/apis/ipranges/googlebot.json
别慌,这其实是一个非常常见的问题,源于系统更新或 Homebrew 变更后,wget
找不到它依赖的某个动态链接库。今天就来手把手教你如何优雅解决。
问题分析:libunistring
被升级或丢失
wget
依赖 libunistring
,而这个库在 Homebrew 更新中可能被替换成了新版本,导致原本的 .dylib
文件路径失效。
macOS 的 dyld
动态链接器尝试在以下路径中寻找 libunistring.2.dylib
:
/usr/local/opt/libunistring/lib/libunistring.2.dylib
/usr/local/lib/libunistring.2.dylib
/usr/lib/libunistring.2.dylib
...
但都找不到,于是程序崩溃。
解决方案一:重新安装 wget(推荐)
brew reinstall wget
这是最直接有效的方法。它会重新编译并链接 wget
,让它使用当前系统中可用的新版本 libunistring
,一劳永逸。
解决方案二:单独补回 libunistring 库
如果你不想重装 wget
,也可以试试安装缺失的库:
brew install libunistring
不过这个方式并不总是有效,因为新版本的 libunistring
可能生成的是 libunistring.5.dylib
或更高版本,而 wget
原本依赖的是 .2.dylib
。所以不如直接走方案一。
解决方案三:换用 curl
,快速绕过
其实如果你只是单纯想下载一个文件,比如:
wget https://developers.google.com/search/apis/ipranges/googlebot.json
完全可以换成 macOS 原生自带的 curl
:
curl -o googlebot.json https://developers.google.com/search/apis/ipranges/googlebot.json
不依赖任何额外库,原地解决一切烦恼。
总结
方法 | 命令 | 说明 |
---|---|---|
✅ 重装 wget | brew reinstall wget | 推荐方式,稳定通用 |
🟡 安装 libunistring | brew install libunistring | 可能修复,但不一定匹配原版本 |
🚀 改用 curl | curl -o 文件名 URL | 最轻便直接,适合下载任务 |
实用建议
如果你是脚本控、自动化达人,建议统一使用 curl
,它默认就包含在 macOS 系统中,更新稳定,不受 Brew 环境变化影响。除非你特定需要 wget
的一些高级参数,否则没必要多此一举。
原始错误案例参考:
wget https://developers.google.com/search/apis/ipranges/googlebot.json
dyld[70620]: Library not loaded: /usr/local/opt/libunistring/lib/libunistring.2.dylib
Referenced from: <3A5CF954-DCBB-3F5A-A4A3-170C341F7E88> /usr/local/Cellar/wget/1.21.3/bin/wget
Reason: tried: '/usr/local/opt/libunistring/lib/libunistring.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/libunistring/lib/libunistring.2.dylib' (no such file), '/usr/local/opt/libunistring/lib/libunistring.2.dylib' (no such file), '/usr/local/lib/libunistring.2.dylib' (no such file), '/usr/lib/libunistring.2.dylib' (no such file, not in dyld cache), '/usr/local/Cellar/libunistring/1.3/lib/libunistring.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/libunistring/1.3/lib/libunistring.2.dylib' (no such file), '/usr/local/Cellar/libunistring/1.3/lib/libunistring.2.dylib' (no such file), '/usr/local/lib/libunistring.2.dylib' (no such file), '/usr/lib/libunistring.2.dylib' (no such file, not in dyld cache)
[1] 70620 abort wget https://developers.google.com/search/apis/ipranges/googlebot.json