Oh, no! I broke ‘apt-get’ in Ubuntu

When using any sort of experimental tools – which anyone in R&D will want – you need to prepare yourself for broken packages and most answers on the web being only partially helpful.  As a computer graphics professional there’s also a good chance the broken packages might be graphics drivers – the very ones you need to see what is broken.

Over the years I’ve had my fair share of PPA-repositories not living up to standards and the worst is when the libraries themselves ( +inexperience ) cause apt to break in a way where the simplest solution:

sudo apt-get autoclean
sudo apt-get update
sudo apt-get -f install

… fails.

From experience it’s always good to install ppa-purge and aptitude together. To do that use the following command in the terminal:

sudo apt-get install ppa-purge aptitude

The reason you should install them together is because if ppa-purge fails, it falls back to aptitude calculations…and if you don’t have aptitude installed ppa-purge breaks your apt-get even more.

  • If you find yourself in that position, you’re going to avoid purging anything and totally integrate the ppa-repository ( completely commit to “becoming their computer”…at least for now ).  Once your apt-get can actually install something, install the two and then work on correcting the packages.  Finally if this is not possible, you have to install apt by hand.

Now that is out of the way, here are some useful commands when using apt / or apt-get in Ubuntu:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get -f install
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get clean

Then there the less direct methods – which involve flushing any cached files of apt or apt-get manually. Such as:

sudo rm /var/lib/apt/lists/* -vf

“Below” apt-get is a program called dpkg, which can be used to help in certain circumstances. I find these two commands useful at times:

sudo dpkg -r --force-all <package-name>
sudo dpkg --purge --force-all <package-name>