How to Force Remove a Debian Package When Post-Install/Purge Scripts Fail (openqrm Case Study)


2 views

We've all encountered packages that refuse to uninstall cleanly due to failed post-installation or pre-removal scripts. The openqrm package in this case fails because it can't locate its configuration file at /usr/share/openqrm/etc/openqrm-server.conf during both installation and removal attempts.

The key indicators from the error messages:

.: 33: Can't open /usr/share/openqrm/etc/openqrm-server.conf
dpkg: error processing openqrm (--configure):
subprocess installed post-installation script returned error exit status 2

This suggests the package's maintainer scripts (both postinst and prerm) are failing because they depend on a configuration file that's either missing or inaccessible.

When standard removal fails, we can manually intervene in dpkg's operation:

# First, move the problematic script aside
sudo mv /var/lib/dpkg/info/openqrm.prerm /var/lib/dpkg/info/openqrm.prerm.bak

# Then force the removal
sudo dpkg --remove --force-remove-reinstreq openqrm

If that doesn't work, we can completely clear dpkg's reference:

sudo dpkg --purge --force-all openqrm

When all else fails, we can edit dpkg's status file directly:

# Backup the status file
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.bak

# Edit the package status
sudo nano /var/lib/dpkg/status

Find the openqrm entry and change its status from install ok half-configured to deinstall ok config-files, then save and run:

sudo apt-get update
sudo apt-get autoremove
sudo apt-get purge openqrm

Sometimes creating the missing file can help the uninstall proceed:

sudo mkdir -p /usr/share/openqrm/etc/
sudo touch /usr/share/openqrm/etc/openqrm-server.conf
sudo apt-get purge openqrm

To avoid similar problems:

  • Always check package scripts before installation (apt-get download package; dpkg -e package.deb)
  • Consider using containers or VMs for testing new packages
  • Maintain regular system backups

After successful removal, clean up residual files:

sudo updatedb
sudo locate openqrm | xargs sudo rm -rf
sudo apt-get autoremove

Remember that force-removing packages can leave your system in an inconsistent state, so use these methods judiciously.


We've all been there - trying to remove a problematic package that simply won't go away because its maintenance scripts keep failing. The openqrm package presents a classic example where both post-installation and pre-removal scripts fail due to missing configuration files.

dpkg: error processing openqrm (--purge):
 subprocess installed pre-removal script returned error exit status 2
.: 33: Can't open /usr/share/openqrm/etc/openqrm-server.conf

The core issue lies in the package's maintenance scripts attempting to access configuration files that either don't exist or have incorrect permissions. In this case, /usr/share/openqrm/etc/openqrm-server.conf is missing, causing the scripts to fail.

The most reliable method is to directly manipulate dpkg's database:

# First, remove the package from dpkg's database
sudo dpkg --remove --force-remove-reinstreq openqrm

# Then purge any remaining configuration files
sudo dpkg --purge --force-remove-reinstreq openqrm

# Finally, clean up any dependencies
sudo apt-get autoremove

For more stubborn cases, we can directly edit dpkg's status file:

# Backup the status file
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.bak

# Edit the status file
sudo nano /var/lib/dpkg/status

Find the openqrm entry and change its status to deinstall ok config-files, then save and run:

sudo dpkg --configure -a
sudo apt-get -f install

Sometimes the simplest solution is to create the missing files that the scripts expect:

sudo mkdir -p /usr/share/openqrm/etc/
sudo touch /usr/share/openqrm/etc/openqrm-server.conf
sudo chmod 644 /usr/share/openqrm/etc/openqrm-server.conf

After creating the missing file, retry the removal:

sudo apt-get purge openqrm

To avoid similar problems in the future:

  • Always check package dependencies before removal
  • Consider using checkinstall instead of direct make install
  • Maintain regular backups of critical system files

Remember that force removal should be a last resort, as it might leave behind orphaned files or configuration items.