Ubuntu – Find out what packages were installed with a particular package

aptdependenciespackage-managementuninstall

I have a simple question.

When you install a package using apt-get install, oftentimes, it will install several dependency packages as well as the main one. I was wondering if there is a way to completely reverse this install. Often, removing the main package will leave several packages behind. For example, I recently installed kubuntu-desktop. Wanting to completely remove it, I had to follow the instructions on this page:

http://www.psychocats.net/ubuntu/puregnome

I would like to know exactly how they obtained that information concerning all the packages to uninstall.

Thanks for any help!

Best Answer

In most cases the autoremove command of apt-get would do the trick, it will remove all packages installed and marked as automatically installed, but not required by any other installed package. This is the preferred and secure method when the master package is not a metapackage.

This is not the case for metapackages like kubuntu-desktop, and this is because packages installed as a consequence of the installation of a metapackage are not marked as automatically installed, so that cannot be remove by autoremove.

Removing all packages marked as dependences of, or recommended by a given metapackage, like kubuntu-desktop, could be dangerous, because some of those packages could be on your system before the installation of the metapackage.

The most secure method to proceed, in my opinion, is an analysis of /var/log/dpkg.log and its ancestors, to see which packages were installed in timestamps around the timestamp of the installation of the given offending package. I suggest a command to get a more terse and cleaned-up view of the concatenation of the involved log files:

less $(ls -rt /var/log/dpkg.log*) |
  awk '$3 ~ /^(install|upgrade|remove|purge)$/' |
  less