Repairing a badly damaged package system in Ubuntu

deb-dpkg

Recently, I did something really stupid and damaged my whole dpkg system. It was pretty bad. I did an “apt-get purge” with a pattern and wildcard and thought it was only going to remove everything around a specific package. It didn’t. It did much much more. Not helping the whole situation was the interrupt I issued when I saw apt going through and yanking stuff that I didn’t want to have removed.

It was bad.

So, I tried to repair the normal ways, but the damage was done. I was unable to complete “apt-get updates” or apt-get “upgrades” and Synaptic Package Manager was not helping. I had some packages in the mix with broken dependencies and everything was a mess. Here are some ways to possibly move through a hosed package system on Ubuntu.

1. See what you can do in Synaptic or Ubuntu Software Center. But, you probably won’t be able to get it going. If you can get in there and purge then reinstall packages, that would be great. At least, give it a shot. If your package system is so damaged that you don’t even have a desktop GUI, than this is off the table anyway.

build-dep5

Synaptic is going to be your best tool. Use custom filters to search and find any broken packages and remove them and reinstall them. Trying to repair or reinstall without removal first will probably not get you the fix you need to get things back on track.

2. You’re probably going to have to deal with the issue through hacking it out in the terminal. In my situation, I broke so many dependencies, that I had to go through dozens and dozens of packages in this way to eventually get me back to stable. The first try should be to work through build-dep options on packages you know are problematic.

build-dep

The build-dep flag on apt-get will try to get the packages it needs, but if things are hosed, this will help but will need to be run against many different packages. If after you run it you are not getting additional packages via download, then keep grinding on other packages that might be popping-up in errors.

build-dep2

Read the errors from what the build-dep kicks back and try to run build-dep against those other packages. If you do make some traction with additional downloads of packages via this method, then you can try to go ahead and try to install.

build-dep4

You may or may not have success with that. If you have packages downloaded through these processes but not installed for whatever reason, you should attempt to have dpkg try and play what you have but might not be able to be fully installed via the apt-get install or build-dep. Issue a –configure -a to play the packages you might have acquired through the process.

3. So, going back and forth with build-dep, install, and dpkg –configure might get you part of the way there to a fully repaired database but it might not get you all the way. Try running some clean, autoclean and autoremove commands with apt-get.

build-dep6

After playing those commands, go back in and try to play the build-dep, install, and dkpg commands

The crazy thing about all of this is that could be just some small package that you need to locate and install to fix the larger issues. It’s like a needle in a haystack. The moral of the story is that the package system is a wonderful way to manage software on Debian-based systems and it rarely gets hosed. You should do everything in your power to not screw it up because if you do, you will be in a tough place probably consisting of playing a ton of repetitive commands against the package database in trying to find that needle in the haystack. The reality is that you will probably have to run many of these commands against all different packages numerous times to eventually crack the code and get the database back in order.

5 Replies to “Repairing a badly damaged package system in Ubuntu”

  1. I did this the other night. Glad I’m not the only one to be so stupid. But why oh why do dpkg and apt-get interpret wildcards differently???!

  2. Thank you very much. After many hours of searching and trial and error I came upon this article. This information fixed my problem fairly quickly. Thanks again, I really appreciate your help with this.

Leave a comment or reply