Debian Package Management – How to Remove Broken Packages

aptitudedebianpackage-management

Recently in a bout of frustration with getting phpmyadmin setup, I decided to start from scratch.

Unfortunately, during the uninstall phase, I was prompted with the root password for mysql which I didn't have on hand at the time. Suffice to say, it informed me that there would be residue components since it couldn't properly clean its database connectors.

When I arrived home, I attempted to remove the package through aptitude purge which turns out to no more potent than aptitude remove in that it saw phpmyadmin, attempted to remove it, and failed since the directories associated with the package were already removed from my earlier attempt.

I tried to reinstall phpmyadmin, but aptitude simply stated that there was no update available, and did nothing, if there were an update, I'd probably run into the same problems regardless.

In this regard, I proceeded to clean up mysql by dropping the database it used, and cleaning it from the user tables. I however have no idea what else is left from the package, or even how to clean the hooks in aptitude.

The result of dpkg --purge

ickronia:/home/ken# dpkg --purge phpmyadmin
(Reading database ... 27158 files and directories currently installed.)
Removing phpmyadmin ...
/var/lib/dpkg/info/phpmyadmin.prerm: line 5: /usr/share/dbconfig-common/dpkg/prerm.mysql: No such file or directory
dpkg: error processing phpmyadmin (--purge):
 subprocess pre-removal script returned error exit status 1
/var/lib/dpkg/info/phpmyadmin.postinst: line 35: /usr/share/dbconfig-common/dpkg/postinst.mysql: No such file or directory
dpkg: error while cleaning up:
 subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
phpmyadmin

On following Gile's advice, I tried to re-install the dependency dbconfig-common

ickronia:/home/ken# aptitude reinstall dbconfig-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
dbconfig-common is not currently installed, so it will not be reinstalled.
dbconfig-common is not currently installed, so it will not be reinstalled.
The following packages are BROKEN:
  phpmyadmin
0 packages upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 0B of archives. After unpacking 0B will be used.
The following packages have unmet dependencies:
  phpmyadmin: Depends: php5-mcrypt but it is not installable
              Depends: dbconfig-common but it is not installable
              Depends: libjs-mootools (>= 1.2.4.0~debian1-1) which is a virtual  package.
The following actions will resolve these dependencies:

Remove the following packages:
phpmyadmin

Score is 121

Accept this solution? [Y/n/q/?] n

*** No more solutions available ***

The following actions will resolve these dependencies:

Remove the following packages:
phpmyadmin

Score is 121

Accept this solution? [Y/n/q/?] n

*** No more solutions available ***

The following actions will resolve these dependencies:

Remove the following packages:
phpmyadmin

Score is 121

Accept this solution? [Y/n/q/?] y
The following packages will be REMOVED:
  phpmyadmin{a}
0 packages upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
Need to get 0B of archives. After unpacking 17.7MB will be freed.
Do you want to continue? [Y/n/?] y
Writing extended state information... Done
(Reading database ... 27158 files and directories currently installed.)
Removing phpmyadmin ...
/var/lib/dpkg/info/phpmyadmin.prerm: line 5: /usr/share/dbconfig-common/dpkg/prerm.mysql: No such file or directory
dpkg: error processing phpmyadmin (--remove):
 subprocess pre-removal script returned error exit status 1
/var/lib/dpkg/info/phpmyadmin.postinst: line 35: /usr/share/dbconfig-common/dpkg/postinst.mysql: No such file or directory
dpkg: error while cleaning up:
 subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
 phpmyadmin
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install.  Trying to recover:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done
Reading task descriptions... Done

ickronia:/home/ken#

It appears that phpmyadmin cleanly cleared out dbconfig-common

ickronia:/usr/share/dbconfig-common# ls -alF
total 12
drwxr-xr-x  3 root root 4096 2011-02-09 08:09 ./
drwxr-xr-x 98 root root 4096 2011-01-20 21:42 ../
drwxr-xr-x  3 root root 4096 2011-01-05 11:08 data/
ickronia:/usr/share/dbconfig-common#

Attempted to dpkg from archives as suggested by Giles

ickronia:/usr/share/dbconfig-common# dpkg -i /var/cache/apt/archives/{dbconfig-common,php5-mcrypt,libjs-mootools}*.deb
Selecting previously deselected package dbconfig-common.
(Reading database ... 27161 files and directories currently installed.)
Unpacking dbconfig-common (from .../dbconfig-common_1.8.46_all.deb) ...
Selecting previously deselected package php5-mcrypt.
Unpacking php5-mcrypt (from .../php5-mcrypt_5.3.3-6_i386.deb) ...
Selecting previously deselected package libjs-mootools.
Unpacking libjs-mootools (from .../libjs-mootools_1.2.5~debian1-2_all.deb) ...
Setting up dbconfig-common (1.8.46) ...
dpkg: dependency problems prevent configuration of php5-mcrypt:
 php5-mcrypt depends on libltdl7 (>= 2.2.6b); however:
  Package libltdl7 is not installed.
 php5-mcrypt depends on libmcrypt4; however:
  Package libmcrypt4 is not installed.
dpkg: error processing php5-mcrypt (--install):
 dependency problems - leaving unconfigured
Setting up libjs-mootools (1.2.5~debian1-2) ...
Processing triggers for man-db ...
Processing triggers for libapache2-mod-php5 ...
Reloading web server config: apache2.
Errors were encountered while processing:
 php5-mcrypt
ickronia:/usr/share/dbconfig-common#

I have a webserver running on php, but I'm willing to risk downtime to get this resolved.

Best Answer

phpmyadmin depends on dbconfig-common, which contains /usr/share/dbconfig-common/dpkg/prerm.mysql. It looks like you've managed to uninstall dbconfig-common without uninstalling phpmyadmin, which shouldn't have happened (did you try to --force something?).

My advice is to first try aptitude reinstall dbconfig-common. If it works, you should have a system in a consistent state from which you can try aptitude purge phpmyadmin again.

Another thing you can do is comment out the offending line in /var/lib/dpkg/info/phpmyadmin.prerm. This is likely to make you able to uninstall phpmyadmin. I suspect you did what that line is supposed to do when you edited those mysql tables manually, but I don't know phpmyadmin or database admin in general, so I'm only guessing.

The difference between remove and purge is that remove just removes the program and its data files (the stuff you could re-download), while purge first does what remove does then also removes configuration files (the stuff you might have edited locally). If remove fails, so will purge.

Related Question