Debian Cleanup Tip #6: Remove automatically installed packages that are no longer needed

Last week we learned how to identify cruft on your Debian system. This week, for the last article in this series, we’ll learn more about automatically installed packages and how to get rid of them when you don’t need them any longer.

APT tracks automatically installed packages

When you install a new package with apt-get/aptitude/synaptic, it’s very common to end up installing many more packages: those are the dependencies of the installed package. Here’s an example:

$ sudo apt-get install pino
The following extra packages will be installed:
  libdbusmenu-glib1 libgee2 libindicate4 libnotify1 notification-daemon
The following NEW packages will be installed:
  libdbusmenu-glib1 libgee2 libindicate4 libnotify1 notification-daemon pino
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 478 kB of archives.
After this operation, 2531 kB of additional disk space will be used.
Do you want to continue [Y/n]? 

After this installation, the 5 “extra packages” will be marked as “automatically installed”. What does this mean? It means that you have not explicitly requested their installation and that the system should be free to remove them as soon as they are no longer needed.

You can verify that this is effectively the case with “apt-mark showauto” (it returns a list of the automatically installed packages).

$ apt-mark showauto |grep libdbusmenu
$ apt-mark showauto |grep pino

Aptitude shows this information with the “A” letter in its interactive interface and in the “aptitude search” output. “aptitude show” has a dedicated field for this:

$ aptitude show libdbusmenu-glib1
Package: libdbusmenu-glib1               
New: yes
State: installed
Automatically installed: yes
Version: 0.3.7-1

In Synaptic, it’s not very visible but once you have selected an installed package, you can verify in the “Package” menu whether “Automatically installed” is checked or not.

APT tells you which packages are no longer needed

Over time, some of those automatically installed packages become unnecessary because the packages that depended on them no longer do. It might be that they are using a newer version of the same library, or they switched to use something else, or they are able to do the task themselves.

Whatever the reason, the original dependency has vanished and the automatically installed package is no longer needed on the system.

Aptitude will automatically remove those unneeded packages the next time you run it but apt-get and synaptic do not.

Apt-get will inform you that some packages are no longer needed and will even tell you how you can get rid of them:

$ sudo apt-get remove pino
The following packages were automatically installed and are no longer required:
  notification-daemon libdbusmenu-glib1 libnotify1 libgee2 libindicate4
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
0 upgraded, 0 newly installed, 1 to remove and 219 not upgraded.
After this operation, 1225 kB disk space will be freed.
Do you want to continue [Y/n]? 
$ sudo apt-get autoremove
The following packages will be REMOVED:
  libdbusmenu-glib1 libgee2 libindicate4 libnotify1 notification-daemon
0 upgraded, 0 newly installed, 5 to remove and 219 not upgraded.
After this operation, 1307 kB disk space will be freed.
Do you want to continue [Y/n]? 

Synaptic will show you the packages that can be removed in a new section name “Installed (auto removable)” if you select the “Status” button in the bottom-left pane.

It’s thus a good habit to get rid of those unneeded package from time to time.

Use this feature to trim down your system

While APT usually sets the “Automatically installed” flag, you can also set it manually. It’s a very simple way to tell the system “I don’t need this package directly, feel free to remove it if nothing else requires it”.

# With apt-get
$ sudo apt-mark markauto libxml-simple-perl
# Or with aptitude
$ sudo aptitude markauto libxml-simple-perl

You can also do it in the interactive interface of aptitude with the key “M” (and “m” for unmarking). To do it in Synaptic, you have to use the menu entry “Package > Automatically installed”.

Many users like to have a minimal set of packages installed but they don’t really know which packages are really important and trying to remove every package to look what happens is cumbersome.

Thanks to this feature, you don’t try removing packages but you flag them as automatically installed. There is few risks in doing so when it concerns libraries (including python/perl modules). If the package is not indirectly needed by one of your important packages, it will be removed by apt-get autoremove, otherwise it’s kept for as long as it’s needed.

I would suggest to not mark as such packages of priority higher or equal to important to avoid nasty surprises (although I say this to not be blamed in case you remove too much, in theory the system should not remove essential components and all dependencies should be complete).

Also be aware of the consequences when you mark “task” packages like “gnome” as automatically installed… it will suggest you to remove your whole desktop. If you want to trim down the default desktop, you should “unmark” the desktop packages that you want to keep:

$ sudo apt-mark unmarkauto gnome-session gnome-panel

Do you want to read more tutorials like this one? Click here to subscribe to my free newsletter, you can opt to receive future articles by email.


  1. Kevin Benko says

    This process brings back memories.
    I transitioned to only using aptitude a few years ago, and the hassles it caused after cleaning out years of “apt-get remove” leftovers, were briefly frightening.
    I would like to comment that mixing the use of apt-get and aptitude are probably a bad idea. Yes, they’re both frontends for dpkg, but aptitude doesn’t “like” the way apt-get fails to clean up after itself. So, when I made the transition to a pure aptitude package management scheme, I had to give up synaptic and learn to use the aptitude curses-interface (and command-line interface).
    Of note, the “packagesearch” GUI package does allow the user to specify an apt-get or aptitude backend, as well as implementing debtags pretty well.

    • says

      Kevin, I mix aptitude and apt-get without any problem. I wonder what you encountered.

      It used to be that apt-get did not set the automatically installed flag, it was first introduced as a feature specific to aptitude… but since Lenny apt-get and aptitude share the same information about automatically installed package.

  2. Dan Wyatt says

    I had this on my Debian webserver.

    Just that aptitude decided the apache, mysql and webmin were “no longer needed” and promptly uninstalled them without my permission.

    And on a desktop Ubuntu system, it decided that the while of Xorg was no longer needed.

    So personally, autoremove has caused nothing but headaches.

    • says

      Aptitude shows a list of actions before performing them, you should double check it before answering “Yes” and letting it go forward.

      Luckily for you, uninstallation doesn’t remove configuration and data, so everything worked again after reinstallation. 🙂

      Obviously this feature is difficult to ignore given the implications it has. If you install, a packaged web app and the webserver and mysql are pulled by the dependencies of this web app, then when you remove that web app (or when its dependencies are loosened) the system might consider apache and mysql as no longer needed… even if you have put lots of data in those services.

      Thus marking some packages as manually installed is also important in such situations.

  3. apt says

    While I believe that accurate diagnosis is half the cure, it would be better to issue aptitude/apt-get with the option –without-recommends/–no-install-recommends in the first place.

    Actually, aptitude and apt-get are complementary utilities, and each one has its own pros and cons. As far as functionality is concerned, you cannot completely replace one with the other.

  4. says

    In my blog you will find a post how to identify packages related to this:
    Essentially, they are about finding packages that you can “markauto” (since other packages depend on them), and then you can check the remaining packages for applications you no longer need.

    I called that “finding packages for deinstallation” since I like to do this when my HDD gets full, and uninstalling software you no longer need sometimes is a nice way of getting that few extra MBs you currently need.