When would you use apt-get remove over apt-get autoremove?

I understand that apt-get remove removes packages and apt-get autoremove is to remove any packages that were installed to fulfil a dependency for a given package. So for example if I installed LibreOffice and it had dependencies on say Java and installed it as part of the installation when I run the command apt-get libreoffice, why would I run the command apt-get remove libreoffice followed by apt-get autoremove? Am I not able to simply run the command apt-get autoremove libreoffice? Or is the combination of apt-get remove and apt-get autoremove for a different purpose?


It depends on how much you trust the dependancy tracker. While almost always correct, there are times when you would want a dependancy to remain, particularly when you are a developer or power user installing software that is not in the repository.

If you always install software through apt-get, without exception, and trust all the dependancies to be correct (which they usually are), then you can use apt-get autoremove and gain a small amount of drive space and a reduced exposure to potential security holes by having it remove packages that no longer have any packages that need them.

But if you install software manually, or develop software, or do not want to deal with a possible dependancy error, then not using autoremove to clear potentially unused packages is probably the safer choice. Regardless of whether you use apt-get autoremove every now and then or not, you will always remove software using apt-get remove Package

For example, if I install AwesomePackage, it may depend on AwesomeLibrary, and thus AwesomeLibrary will get automatically installed as a dependancy. When I remove AwesomePackage using autoremove, as long as no other package has AwesomeLibrary as a dependancy it will be uninstalled as well. But if SuperPackage also requires AwesomeLibrary, or if I had installed AwesomeLibrary explicitly myself rather than having it come in automatically as a dependancy (apt-get install AwesomeLibrary), then autoremove would not get rid of it.

The reason it is not the default is that having AwesomeLibrary on the system, unused, is a very minor issue. It will almost never cause problems, and most dependancies don't take up much space. There are exceptions, but the times when removing a dependancy will cause problems outnumber the times when it will solve or prevent a problem.


You can find the description of remove, autoremove, purge, clean and autoclean, as well as the syntax in the manpages for apt-get: man apt-get.

If you are still unsure after reading it though (I was) the best way to clarify it is to try it out.

Below is an example of a full dependency tree for vim:

vim-dependency-tree

You can get it with:

apt-rdepends -d vim > vim.dot
dotty vim.dot

You can also get a list of the immediate dependencies using apt-cache depends (see Declaring relationships between packages for more info):

$ apt-cache depends vim
vim
  Depends: vim-common
  Depends: vim-runtime
  Depends: libacl1
  Depends: libc6
  Depends: libgpm2
  Depends: libselinux1
  Depends: libtinfo5
  Suggests: <ctags>
    exuberant-ctags
  Suggests: vim-doc
  Suggests: vim-scripts

So it looks like vim depends on a number of packages, let's attempt to install it with apt-get install and see what happens:

$ sudo apt-get install vim
...
The following extra packages will be installed:
  vim-common vim-runtime
Suggested packages:
  ctags vim-doc vim-scripts
The following NEW packages will be installed:
  vim vim-common vim-runtime
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
After this operation, 25.1 MB of additional disk space will be used.
Do you want to continue [Y/n]? n

In order to get vim to work we need vim-common and vim-runtime packages and apt-get will take care of it. We can verify it with dpkg -s pkg... (see man dpkg for more info on statuses):

$ sudo dpkg -s libc6
Package: libc6
Status: install ok installed        // we already have it, no need to install

$ sudo dpkg -s vim-common
Package: vim-common
Status: deinstall ok config-files   // we don't have it, have to install

Just as we checked what vim depends on, we can also check what other things depend on the same packages as vim using apt-cache rdepends. We should see vim among (possibly) other things:

$ apt-cache rdepends vim-common
vim-common
Reverse Depends:
  vim-latexsuite
  vim-addon-manager
  vim-tiny
  vim-nox
  vim-gtk
  vim-gnome
 |vim-dbg
  vim-athena
  vim                               // there it is

Let's continue with the installation. Once we have installed vim we can experience the difference between remove and autoremove. Let's attempt to remove first:

$ sudo apt-get remove vim
...
The following packages will be REMOVED:
  vim
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,922 kB disk space will be freed.
Do you want to continue [Y/n]? n

apt-get remove would then remove vim but not its dependencies leaving them behind. Let's now try to remove one of the vim's dependencies:

$ sudo apt-get remove vim-runtime
...
The following packages will be REMOVED:
  vim vim-runtime
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 24.8 MB disk space will be freed.
Do you want to continue [Y/n]? n

This would remove the dependency vim-runtime as well as the package that depends on it, namely vim. Out of curiosity, let's see what would happen if we removed a dependency that is lower on vim's dependency tree:

$ sudo apt-get remove libgpm2
...
The following packages were automatically installed and are no longer required:
  libgtkglext1 libqtassistantclient4 libtiff-tools libtiff5 python-qt4
  python-sip python-sqlalchemy python-sqlalchemy-ext
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  anki cheese gimp gimp-gmic gimp-plugin-registry gnome-control-center      // !
  gnome-media gnome-video-effects gstreamer0.10-plugins-good libaa1         // !
  libcheese-gtk21 libcheese3 libgpm2 mplayer quodlibet vim vlc w3m          // !
0 upgraded, 0 newly installed, 18 to remove and 0 not upgraded.
After this operation, 63.1 MB disk space will be freed.
Do you want to continue [Y/n]? n

It would remove vim and lots of goodies!

Let's proceed with apt-get remove vim then. Once we have done it we should have some leftovers. If we now try autoremove we can see:

$ sudo apt-get autoremove
...
The following packages will be REMOVED:
  vim-common vim-runtime
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 23.2 MB disk space will be freed.
Do you want to continue [Y/n]? y

These are the two packages apt-get remove left behind even though nothing else needed them.

Experimented with apt-get 0.9.7.9.


According to this: http://ubuntuforums.org/showthread.php?t=996053 autoremove will remove all packages that other programs do not need. You would do 'apt-get autoremove', not 'apt-get autoremove libreoffice'. Also removing unneeded packages does not just free up a little disk space, it reduces the 'attack surface' of your system.


remove will delete the specified program whereas autoremove will include dependencies otherwise not used anymore.

Also, If you'd like to free up drive space, a useful and safe command is...

sudo apt-get clean

That removes the aptitude cache in /var/cache/apt/archives