84

I can not remove broken package. Use the following command: sudo apt-get -f install but I get the following response:

Preparing to unpack .../nodejs_0.10.28-1chl1~trusty1_amd64.deb ...
Unpacking nodejs (0.10.28-1chl1~trusty1) over (0.10.25~dfsg2-2ubuntu1) ...
dpkg: error processing archive /var/cache/apt/archives/nodejs_0.10.28-1chl1~trusty1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/man/man1/node.1.gz', which is also in package nodejs-legacy 0.10.25~dfsg2-2ubuntu1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Processing triggers for man-db (2.6.7.1-1) ...
Errors were encountered while processing:
 /var/cache/apt/archives/nodejs_0.10.28-1chl1~trusty1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried various commands like

 2015  sudo apt-get clean
 2020  sudo dpkg --configure -a
 2023  sudo apt-get autoremove
 2034  sudo apt-get upgrade && sudo apt-get -f install

But I did not get any result. I can not install synaptic. Any ideas how can I remove the broken package ?

1
  • 1
    Here few answers has suggested --force-remove-reinstreq and --force-overwrite. Please note that you should use these two (especially the first one) only if you are a Linux expert , because it can break you system completely.
    – g_p
    Dec 2, 2016 at 3:49

13 Answers 13

111

run this command to remove broken packages in ubuntu.

sudo dpkg --remove --force-remove-reinstreq package_name 

after removing package update your system with command

sudo apt-get update

restart system after successfully updation.

6
  • 12
    This command should always be avoided as it breaks you system more than it repairs
    – rancho
    Jun 19, 2016 at 20:03
  • 2
    @rancho depends on what package it is.
    – Philip
    Jul 6, 2016 at 13:18
  • nice one, the way you gus always write package_name, yet i see a list of 900 lines in a crazy format, for example : Broken libopencv-highgui2.4v5:amd64 Conflicts on libopencv-highgui2.4 [ amd64 ] < 2.4.8+dfsg1-2ubuntu1 > ( libs ). waiting on LTS has really done this crazy trick to me.
    – nyxee
    Aug 15, 2017 at 7:35
  • 1
    @rancho "it breaks you system more than it repairs" can you elaborate? man dpkg does not help a lot. May 9, 2019 at 16:45
  • 2
    I think reinstalling the broken package would have much less change of breaking the system. Try sudo apt install --reinstall packagename-here. After the package has been succesfully reinstalled and is not longer a broken one, you can remove it normally. Jul 14, 2021 at 7:11
21

Open your terminal and use following command

sudo dpkg --purge nodejs-legacy
sudo apt-get install -f

It should solve your problem.

19

This fixed my problem:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_0.10.28-1chl1~trusty1_amd64.deb
1
  • Really helpful. I almost lost many packages that depend on a broken package. I only overwrited that broken one then everything solved
    – fsevenm
    Feb 5, 2020 at 6:51
18

I've found that:

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

Works best. If it gives you an error that it won't remove a package because it is depended on by another package, remove that other package as well. You'll have to repeat this step several times and then reinstall your deleted packages.

The force-remove-reinstreq is THE "nuclear option" of deleting a package. It only fails if there is another package depending on the one you're about to delete -- Again, in that case, deleted the depending package too.

7
  • THE nuclear option worked where purges, cleans, reinstalls, autoremoves, via both dpkg and apt-get failed. Thank you. Aug 22, 2016 at 14:54
  • This is the best solution if you just want to nuke everything and start over. Saved me lots of time! (I also used --purge after --remove) Jan 24, 2017 at 20:22
  • 1
    plase, can u give some hints on how to fill that package_name when we have like 1000+ lines (some duplicate) in the apt log files..
    – nyxee
    Aug 15, 2017 at 7:36
  • 1
    "remove that other package as well" ! +1
    – Marecky
    Feb 3, 2021 at 21:31
  • Use dpkg -l to list packages Dec 7, 2021 at 4:51
11

If you have a broken dependency (which I have encountered with openjdk), you will want to purge the package and force it to skip over dependency problems:

sudo dpkg -P --force-depends package_name

I found the answer on another forum

3
  • 1
    This fixed my problem! Thanks for your answer
    – HKTonyLee
    Sep 20, 2022 at 18:46
  • 1
    I could kiss you! thank you, thank you, thank you.
    – elviejo79
    Nov 4, 2022 at 3:35
  • This is the only solution that worked for me after trying a lot of options to completely uninstall a Python version I compiled manually. Thank you so much.
    – Tedpac
    Jun 16, 2023 at 4:24
11

NOTE: The following command will remove the installation and removal scripts including the list files. It won't remove the package, nor it will fix anything, it will just make dpkg forget about the error message.

rm /var/lib/dpkg/info/<package_name>.*

example:

rm /var/lib/dpkg/info/elasticsearch.*

2
  • This answer helped me find a less drastic solution to the problem. I added set -x to the top of the /var/lib/dpkg/info/$PKG_NAME.postrm to echo what is was executing. This showed that it was failing while trying to deluser. I manually deleted the user, commented the offending line, and was then able to successfully uninstall the package. Apr 16, 2021 at 16:17
  • The accepted answer does not fix my problem because it get stuck on pre-removal script anyway
    – xrfang
    Feb 14, 2023 at 8:48
8

None of the above worked for me. Eventually I edited /var/lib/dpkg/status and removed the packages from there.

However, I would not advise this. It's just an option if all else fails.

1
  • 4
    This seems to be the only thing that worked for me. Even the so called 'nuclear option' of --force-remove-reinstreq couldn't delete the offending package. Thank you, sir.
    – alex
    Mar 15, 2018 at 10:00
5

Here's one:

update your package list like this

 sudo apt-get update

then cleanup any partial packages

 sudo apt-get autoclean

Now clean the apt cache

 sudo apt-get clean

Now remove any unnecessary dependancies

 sudo apt-get autoremove

from the command above, you can identify any broken packages and forcefully remove it like this

 sudo dpkg --remove --force-remove-reinstreq package_name

Finally mopup any other packages with dependacies

 sudo apt-get -f install 

Tell me how it goes.

4
  • I think this command is incorrect: `sudo dpkg --remove -force --force-remove-reinstreq package_name. Apr 1, 2015 at 21:39
  • Ji...so which one is the correct way?
    – Zuko
    Apr 2, 2015 at 3:57
  • Thanks a lot. So many suggestions, but only yours `sudo apt-get autoremove -f' helped for Ubuntu16.04 broken squid package.
    – Andrew
    Apr 27, 2020 at 18:54
  • 1
    @nine9five I'm glad you are sorted. Enjoy your day
    – Zuko
    Apr 29, 2020 at 9:30
3

Open your terminal , and paste these line after line

sudo rm -rf  /var/cache/apt/archives/nodejs_0.10.28-1chl1~trusty1_amd64.deb
sudo apt-get autoclean
sudo apt-get update
sudo apt-get upgrade

then try again

3

The same error repeats If we do apt-get clean and apt-get -f install unless we remove the junk data from /var/lib/dpkg/status file in Ubuntu.

Suppose we need to remove apache broken package. Initially we have to open the status file and search for the package apache. Remove the entire package description and save the status file. Then try using apt-get -f install and apt-get clean.

2

None of the above worked for me

I used sudo aptitude.

It found the error immediately and offered options. You select and it fixes it.

1
  • also fixed it for me on debian - this was the only working solution for me. None of the comments before worked for me! Thanks!
    – Hirbod
    Dec 14, 2018 at 23:21
1

I had a problem with broken kodi package. I opened synaptic package manager and used the "broken" filter to locate the package and marked it for complete removal. It worked like a champ.

0
  1. query all the packages that are installed today or yesterday awk -v foo=$(date '+%Y-%m-%d') -v bar=$(date -d "yesterday" '+%Y-%m-%d') '($1==foo || $1==bar) && $3~/^install$/ { print $4 }' /var/log/dpkg.log
  2. wine-qqintl:i386 caused the problem, so I remove the package sudo dpkg -r wine-qqintl:i386

  3. done.

1
  • 2
    ok, we can get recently installed packages like that, but this doesn't answer the question which asks how to remove broken packages
    – Zanna
    Oct 20, 2016 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .