88

There was an error when I tried to remove a package, so it was left in a broken state. I tried the following:

sudo dpkg --remove --force-remove-reinstreq rvm

Output:

(Reading database ... 41743 files and directories currently installed.)
Removing rvm (1.29.3-1) ...
bash: rvm: command not found
dpkg: error processing package rvm (--purge):
 subprocess installed pre-removal script returned error exit status 127
Errors were encountered while processing:
 rvm

.

sudo dpkg --purge rvm

Output: same as above

sudo dpkg -i --force-overwrite package

Output:

dpkg: error processing archive rvm (--install):
 cannot access archive: No such file or directory
Errors were encountered while processing:
 rvm

Is there a way to force remove it, ignoring all errors? I'm using Ubuntu 16.04 on WSL.

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284

6 Answers6

216

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
Community
  • 1
  • 1
emont01
  • 3,010
  • 1
  • 22
  • 18
  • 7
    This worked for me, and also with a wedged package on WSL. Not sure how the other "how to install things" answers are relevant when the question is about removing a broken package. – Bruce Oct 31 '18 at 16:40
  • 2
    Step 2 proved sufficient for my case. – dannyman May 24 '19 at 22:03
  • 1
    Thanks. This saved me BIG TIME!. I am using ubuntu 18.04 under windows 10 (as WSL) and trying to install docker and your answer helps me while installing docker-ce package manually. – Noha Salah Apr 10 '20 at 08:34
  • I had a problem because of some non-UTF8 characters that had somehow been inserted into /var/lib/dpkg/status file, causing broken package errors. I deleted those packages (along with the non-UTF8 characters) from the file, and then did Step 2. Solved my problem! – Abhirup Das Jun 06 '20 at 06:14
  • You don't need the `--force-remove-reinstreq` stuff, once those files are gone it's good... – rogerdpack Jul 15 '20 at 16:51
  • 2
    sudo dpkg --purge --force-all worked for me. – Raydelto Hernandez Aug 12 '20 at 13:30
  • I was cured at `sudo dpkg --purge --force-all `. You are my best friend now. – toraman Dec 10 '20 at 14:18
  • 4
    the pirpime website linked above is offline for the moment but it's archived here: https://web.archive.org/web/20201112035511/http://www.piprime.fr/1480/manually-remove-broken-package-debian-ubuntu/ – HongPong Oct 03 '21 at 01:28
  • This helped me in removing salt minion and it's leftover packages – Ajay Sharma Nov 15 '21 at 08:53
2
  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!

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
Ideacon
  • 53
  • 1
  • 2
    This does not answer the question! Rather, it's giving another way of installing packages. – Rohan Bari Jan 21 '21 at 12:49
  • Synaptic is different, and handles things differently. Sometimes synaptic fixes things apt doesn't. So it might actually be a proper answer..! – stolsvik Mar 10 '22 at 09:24
  • Not really a answer, people only face this problem because apt intall is no longer useable due to broken package, this offers a solution to a problem after you already fixed the problem. As you are not able to run apt-get install synaptic. – Mairold Kunimägi Jan 31 '23 at 10:50
1

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
WeezyKrush
  • 464
  • 5
  • 11
1

sudo apt remove -f <package_name>

Ex: sudo apt remove mongo* will remove all mongo db packages.

0

I had a similar issue where a package was missing files, and hence could not be removed. The error message was "Stopping Service. Cannot stop ***.service, service is not running" Service is not running since service file is missing.

Shouldn't it be easier to purge the package then? I guess not.

Still: run aptitude

sudo aptitude

find the package in question, check its info, verify which versions exist. Install a different version from the one you have presently (ideally one patch version up or down from what you have to avoid too much change) - it will ask you what to do with the missing files - choose to replace from the version being installed

sudo apt-get install <package>=<version>

Once all such missing files are replaced, you should be able to do standard purge

sudo apt-get purge <package>
-8

Execute the command as a root

sudo apt-get install -f

You need elevated privileges for the package manager.

Abdelhak
  • 176
  • 2
  • 12