Removing packages only installed as dependancies and no longer needed (Ubuntu, Debian)

We’ve all installed packages, using apt-get, where it’s installed a lot of other packages to satisfy dependancies.

But what if you remove that package at a later date that needed all of those dependancies?  You’ll probably find it’s left the dependancies installed.. and if you’ve not installed any other packages which also need those dependacies, they’re just taking up hard drive space.

It’s easy to remove them, though – after all, you no longer need them so why keep them?

The command is simple (and needs to be run as root):

apt-get autoremove

… and that’s it.  The man page entry for this command:

“autoremove is used to remove packages that were automatically installed  to satisfy dependencies for some package and that are no more needed.”

So the next time you install a package which needs lots of dependancies, and you decide you want to remove it for whatever reason, remember to run apt-get autoremove afterwards!

Warning: You do need to be careful when running this – always check which packages it’s proposing to uninstall before confirming.  I have seen reports of random packages being removed, breaking the entire system – even though it is an officially supported feature of apt-get, and it can be very useful, use it with caution.