apt-get install时 dpkg报错解决

ubuntu 14LTS 上在用apt-get install 安装php5-mysql时,出现了

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.  
1 not fully installed or removed.  
After this operation, 0 B of additional disk space will be used.  
Do you want to continue [Y/n]?  
...
...
dpkg: error processing package xxx (--configure):  
...
...
Errors were encountered while processing:  
 php5-mysql

根据报错提示有一个软件未完全安装或卸载,再下面就是dpkg解包错误。

如下命令尝试自动修复有问题的包,未果。

apt-get --autoremove  
apt-get --autoclean  

多次搜索后发现原因是由于在 /var/lib/dpkg/info 关于php5-mysql的中某一个或几个文件出现损坏,此处,删掉php5-mysql的相关文件,然后重新尝试纠正具有破坏的依赖关系,如下执行即可:

rm -f php5-mysql.*  
apt-get install -f  

其他软件安装时如果出现了dpkg报错,也可用此方法进行尝试解决。

[参考文章]

  1. https://www.cnblogs.com/anpengapple/p/5098960.html
  2. https://blog.csdn.net/jisuanji2121/article/details/73028347
  3. https://jingyan.baidu.com/article/b2c186c8e95d1dc46ef6ff0c.html