Voir cette page en français

Jul 31 2011

Manually remove a broken package on Debian/Ubuntu

Category: Asymptote

The problem

Sometimes a Debian or Ubuntu package does not install correctly and can not be uninstalled. The system update is so completely broken that conventional commands, whether apt-get, ability or dpkg, not corrects the problem.

For example the package slapd was in this case in Debian some time ago.
If one attempts to remove the package slapd, the package manager asks to reinstall it properly :

[root@master]$ aptitude remove slapd
The following packages will be REMOVED:
  slapd
Need to get 0 B of archives. After unpacking 4162 kB will be freed.
dpkg: error processing slapd (--remove):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
configured to not write apport reports
Errors were encountered while processing:
 slapd
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install.  Trying to recover:
  

it is unfortunately not possible to reinstall or to terminate the installation :

[root@master]$ apt-get install slapd
[…]
Preparing to replace slapd 2.4.25-1+b1 (using .../slapd_2.4.25-1.1_i386.deb) ...
sed: can't read /etc/ldap/slapd.d/cn=config.ldif: No such file or directory
invoke-rc.d: initscript slapd, action "stop" failed.
dpkg: warning: subprocess old pre-removal script returned error exit status 2
dpkg - trying script from the new package instead ...
sed: can't read /etc/ldap/slapd.d/cn=config.ldif: No such file or directory
invoke-rc.d: initscript slapd, action "stop" failed.
dpkg: error processing /var/cache/apt/archives/slapd_2.4.25-1.1_i386.deb (--unpack):
 subprocess new pre-removal script returned error exit status 2
configured to not write apport reports
Backing up /etc/ldap/slapd.d in /var/backups/slapd-2.4.25-1.1... done.
grep: /etc/ldap/slapd.d/cn=config/olcDatabase*: No such file or directory
sed: can't read /etc/ldap/slapd.d/cn=config.ldif: No such file or directory
invoke-rc.d: initscript slapd, action "start" failed.
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/slapd_2.4.25-1.1_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
  

The solution : manually uninstall the package

To manually uninstall the broken package run the two commands below as root in Debian, preceded by sudo in Ubuntu :

mv /var/lib/dpkg/info/PAQUET.* /tmp/
dpkg --remove --force-remove-reinstreq PAQUET