Clean up your unneeded packages

by Stephen Fluin 2009.02.17

Over the course of a few years in the life of a standard debian/ubuntu user, a lot of packages are going to be installed and removed on a trial basis. One of the negative side effects of this process is the possibility that packages are going to be marked "manual install" when they shouldn't be.

The effect of this "manual install" is that your system thinks the package is important and needs to be kept on your system, when it might not necessarily need to be. Thankfully there are ways of cleaning this up. The command below uses aptitude to present a list of non-essential packages that are marked as manually installed. It then iterates over the list and for each package, it will either mark it automatic if the change would not result in a change to your installed packages, or it asks you if you are sure you want to make the change because it would result in auto-removal of a package.

for pkg in $(aptitude search ~i | grep -v "i A" | cut -d " " -f 4) ; do
  echo "--Package being marked as auto: $pkg"
  sudo aptitude markauto $pkg

As usual, be careful. You need to interactively use this command because it will ask you whether or not you want to keep all of your manually installed programs, including things such as games, browsers, tools, etc.