pacman 升级软件包提示 "failed to commit transaction (invalid or corrupted package)"
这可能是 keyring 软件包过时导致的.

很久没打开 WSL 2 里面的 Arch Linux, 想着更新一下软件包, 执行 pacman -Syu, 遇到 “signature is marginal trust” “failed to commit transaction (invalid or corrupted package)” 等错误.

执行 pacman -Syu 报错 “Failed to commit transaction (invalid or corrupted package)” 观察输出的信息, 似乎提到了 “签名” “信任” 的问题 (signature … is marginal trust).

可能当时自己搜索时关键字没提供完整或是什么问题, 总之没能解决问题, 于是可怜兮兮去问友人, 然后被告知 ArchWiki 上就有, 还被责怪为什么不先去看 Wiki.

友人回复挺快, 而且 ArchWiki 的 Pacman 页面 上边 Troubleshooting 章节下的第二点就是, 估计也是常见的问题. ArchWiki 上边的其他记录也挺全面详实的.

果然遇事还是应该先看 Wiki, 写这篇博文也是为了记录这个教训.

总之, 在 ArchWiki 的对应部分, 也就是 “Failed to commit transaction (invalid or corrupted package)” error, 可以看到这样一段话:

That same error may also appear if archlinux-keyring is out-of-date, preventing pacman from verifying signatures. See Pacman/Package signing#Upgrade system regularly for the fix and how to avoid it in the future.

大概意思是说:

同样的错误也可能是 archlinux-keyring 这个软件包过时所导致的, 使得 pacman 无法进行签名验证. 参考 Pacman/关于软件包签名#定期更新系统 以获得问题的解决方案以及如何避免在未来遇到同样问题.

点进文字中链接的这个页面可以看到:

Upgrading the system regularly via pacman#Upgrading packages prevents most signing errors. If delay is unavoidable and system upgrade gets delayed for an extended period, manually sync the package database and upgrade the archlinux-keyring package before system upgrade:

# pacman -Sy archlinux-keyring && pacman -Su

This command is not considered a partial upgrade since it syncs the package database and upgrades the keyring package first. Both must be processed just before starting system upgrade to ensure signatures of all upgraded packages can be properly verified.

大概意思是说:

根据 pacman#升级软件包 中的内容定期升级系统可以避免大部分的签名错误. 如果遇到了不可避免的延迟, 导致系统升级 (system upgrade) 比平时延迟了更长一段时间, 则需要使用如下命令, 在系统升级前手动同步软件包数据库并升级 archlinux-keyring 软件包:

pacman -Sy archlinux-keyring && pacman -Su

这个命令并不会被视作一次 “部分升级”, 因为它在同步了软件包数据库后只是首先安装了 keyring 软件包. 在进行系统升级前, 两项工作都必须进行, 以确保所有被升级的软件包的签名都能被正确验证.

如上, 签名无法验证导致软件包提示损坏的问题应该就能够解决了.


Last modified on 2022-09-03