Package cleanup: tiny hints
If you use some system for long enough, passing through various release upgrades, installing and uninstalling packages - basically living and using - your system might start be bloated with various remnants of dependencies, unneeded packages, dragging back some relicts or even blocking some new deps. Very unpleasant fact.
To keep the system slick and robust you can rely on built-in debian/ubuntu package manager's feature: dependency tracker. And the fact that APT is already tuned to keep only what you asked to keep, neither more nor less. Package is assumed as Used if it is either installed explicitly by you or is a dependency to other package. Otherwise unused package will be automatically removed once you execute some aptitude
task.
First thing might be disabling recommended packages. Each package has hard dependencies and optional - feature enhancements. By defaults those optioanls (Recommended) are enabled in Ununtu's apt. Hence if you want to keep only bare minimum - switch it off setting to false:
$ grep Recommends /etc/apt/apt.conf.d/* /etc/apt/apt.conf.d/99synaptic:APT::Install-Recommends "false";
There is another option which can keep package when it is unused, you might want to tune it or switch it off if desired:
$ grep used /etc/apt/apt.conf.d/* /etc/apt/apt.conf.d/05aptitude:#aptitude::Keep-Unused-Pattern "^linux-image.*$ | ^linux-res tricted-modules.*$ | ^linux-ubuntu-modules.*$";
Next task is more time consuming. Many how-tos and other descriptions are usually disregarding built-in dependency tree of the OS and provide extensive list of packages which includes all the possible and probable deps. When you install some package this way you'll pin all these packages to the system, even if later you decide to remove the original software package. To fix this you need to unpin them and let the system (aptitude) to clean them up.
First step will be to list packages which are expliticly installed and chose those you have no idea why they are there for potential cleanup. Second step then will be to clean them off the explicit install flag (in fact it is called to mark packages as auto installed - by some dependency).
List packages having installed
flag and not marked with auto
flag:
:~# aptitude search '?and(~i,?not(~M))'
Chose packages and mark them with auto
flag:
:~# aptitude markauto python2.7 python3.3
On this step if package is not listed as a dependency for any other installed package - it will be automatically cleaned up from the system. You can execute some batch operations if you want. Let say to mark all python packages (you're not python coder, are you?):
:~# aptitude markauto `aptitude search '?and(~i,?not(~M))' | awk '/^i.. python/{print$2}'`
Or to mark all libraries except development packages and perl libs as auto (you're perl and C coder, aren't you?):
:~# aptitude markauto `aptitude search '?and(~i,?not(~M))' | awk '/^i.. lib/{print$2}'|egre p -v -- '-(dev|perl)'`
You can exclude more packages with more complex grep exclusion patterns if aptitude deprives of something important.
If after all your struggles you still see in search results packages marked 'id' (installed, could be deleted) - you may simply clean them up with
$ aptitude purge $(aptitude search '~g' | awk '/^id/{print$2}')Link... Sat Jan 26 17:57:42 2013 Upd.: Sat May 25 10:04:36 2013