Removing broken packages in Ubuntu

  1. Install synaptic package manager.

    sudo apt-get install synaptic
    
  2. Open synaptic package manager and search for the package which you want to remove or install or change

Done!


I faced this problem with a broken package, rvm. I tried many things like sudo apt install -f and sudo dpkg --purge --force-all rvm but nothing worked. Finally I managed to find a blog post that explains how to remove broken packages on Debian/Ubuntu.

Here are the steps.

  1. Find your package in /var/lib/dpkg/info, for example using: ls -l /var/lib/dpkg/info | grep <package>

  2. Move the package folder to another location, like suggested in the blog post I mentioned before.

     sudo mv /var/lib/dpkg/info/<package>.* /tmp/
    
  3. Run the following command:

     sudo dpkg --remove --force-remove-reinstreq <package>
    

So as an example I solved my problem by executing the following commands in a terminal:

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

so in my case perl-modules-5.22 was corrupt. I followed the steps in the accepted answer, but this did not resolve my issue.

to fix I additionally had to:

sudo apt remove -f perl-modules-5.22
sudo apt upgrade -y

Tags:

Ubuntu

Apt