dpkg 卸载时出现 error processing package
目录
之前在 wsl 上面安装了 n2n,但是因为 wsl 上面没有 systemd,导致了安装失败。在卸载的时候又提示:
➜ sudo dpkg -r n2n
(Reading database ... 110162 files and directories currently installed.)
Removing n2n (3.0.0-1038) ...
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error processing package n2n (--remove):
installed n2n package pre-removal script subprocess returned error exit status 1
Errors were encountered while processing:
n2n
后面又试了很多方法都没有卸载成功,因为其实无论是通过 apt 还是 dpkg,最终都还是会落到 dpkg 上面,然后在卸载的时候会有一个类似生命周期的东西,可以在卸载前和卸载后运行脚本,这些脚本在 /var/lib/dpkg/info/
下面以{package_name}.*
命名。
以 n2n 为例:
➜ sudo ls /var/lib/dpkg/info/n2n.*
/var/lib/dpkg/info/n2n.conffiles
/var/lib/dpkg/info/n2n.list
/var/lib/dpkg/info/n2n.md5sums
/var/lib/dpkg/info/n2n.postinst
/var/lib/dpkg/info/n2n.postrm
/var/lib/dpkg/info/n2n.preinst
/var/lib/dpkg/info/n2n.prerm
/var/lib/dpkg/info/n2n.templates
所以我们只需要编辑 /var/lib/dpkg/info/n2n.prerm
,在其中去掉 systemd 相关的指令就可以正常卸载了。