Strategic IT Consulting and Implementation Services

Repairing a badly damaged package system in Ubuntu

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.

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.

sudo apt-get build-dep <package>

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.

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.

sudo apt-get install <package>

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.

sudo dpkg --configure -a

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.

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove

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

sudo apt-get build-dep <package>
sudo apt-get install <package>
sudo dpkg --configure -a

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.

About the author

Jonathan Mergy


Strategic IT Consulting and Implementation Services