Ubuntu 11.10 – How to Completely Remove a Package

The Solution

There are three solutions to this problem:

  1. Don’t install the Recommended packages. This isn’t always a good idea since the recommended packages are there to give you a “complete” experience. As well, there are often Extra packages that are needed by the install and they get installed anyway (but not always removed during an uninstall).
  2. Record the recommended and extra packages being installed so you know what to uninstall if you need to. This implies you already know about the “uninstall problem” – which implies you’re not likely reading this tutorial.
  3. Find out which extra packages were installed and manually remove them.

How To Not To Install Recommended Packages

Adding the flag / switch --no-install-recommends to the apt-get command will prevent most, but not all, additional packages from being installed. In the example below, a number of Extra packages (blue) are being installed with lubuntu-desktop (yellow) – these packages are needed for lubuntu-desktop to run correctly:

richard@richard-VirtualBox:~$ sudo apt-get install --no-install-recommends lubuntu-desktop
[sudo] password for richard:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  elementary-icon-theme gnome-icon-theme-full leafpad libfm-data
  libfm-gtk-data libfm-gtk1 libfm1 libimlib2 libmenu-cache1 libobrender27
  libobt0 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras
  lubuntu-artwork lubuntu-core lubuntu-default-settings lubuntu-icon-theme
  lxdm lxlauncher lxmenu-data lxpanel lxsession lxterminal openbox pcmanfm
  plymouth-theme-lubuntu-logo plymouth-theme-lubuntu-text wvdial
Suggested packages:
  evince-gtk menu ttf-dejavu libxml2-dev
Recommended packages:
  amixer scrot galculator abiword ace-of-penguins audacious audacious-plugins
  chromium-browser gdebi gnome-mplayer gnome-time-admin gnumeric gpicview
  guvcview hardinfo lxappearance lxappearance-obconf lxinput lxkeymap
  lxpanel-indicator-applet-plugin lxrandr lxsession-edit lxshortcut lxtask
  mtpaint ntp osmo pidgin pidgin-microblog sylpheed sylpheed-doc sylpheed-i18n
  sylpheed-plugins transmission xfburn xfce4-power-manager xpad xscreensaver
  lxde-common locales-all openbox-themes
The following NEW packages will be installed:
  elementary-icon-theme gnome-icon-theme-full leafpad libfm-data
  libfm-gtk-data libfm-gtk1 libfm1 libimlib2 libmenu-cache1 libobrender27
  libobt0 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras
  lubuntu-artwork lubuntu-core lubuntu-default-settings lubuntu-desktop
  lubuntu-icon-theme lxdm lxlauncher lxmenu-data lxpanel lxsession lxterminal
  openbox pcmanfm plymouth-theme-lubuntu-logo plymouth-theme-lubuntu-text
  wvdial
0 upgraded, 30 newly installed, 0 to remove and 19 not upgraded.
Need to get 16.1 MB of archives.
After this operation, 64.2 MB of additional disk space will be used.
Do you want to continue [Y/n]?  

Unfortunately, uninstalling the lubuntu-desktop package will not uninstall those extra packages:

richard@richard-VirtualBox:~$ sudo apt-get remove --auto-remove lubuntu-desktop
[sudo] password for richard:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  lubuntu-desktop
0 upgraded, 0 newly installed, 1 to remove and 123 not upgraded.
After this operation, 32.8 kB disk space will be freed.
Do you want to continue [Y/n]? 

This is because none of the extra packages depend on lubuntu-desktop to work, but lubuntu-desktop depends those packages to work.

While the --no-install-recommends doesn’t solve the problem ,it is still a good option to eliminate installing applications you don’t want or need.

How To Record The Extra and Recommended Packages Being Installed

These instructions are for Ubuntu 11.10, using the Unity interface and the Terminal application.

I expect the instructions to be similar for other environments, but no guarantee is made.

When you install using apt-get, you are presented with a list of the packages to be installed. If you record this information, you can use it later to do a complete uninstall.

1) Select the text describing the packages being installed (this is part of the information apt-get shows you when it asks you if you want to continue):

  • Place the mouse cursor just after the final line (Do you want to continue [Y/n]?).
  • Press and hold the left mouse button.
  • While pressing the left mouse button, drag the mouse upwards to select the text (it doesn’t have to be super accurate, we will edit the text later. What is important is that you capture all the package names being installed).
  • Release the left mouse button.
  • Click the right mouse button and select Copy from the popup menu.

2) Paste the selected text into a word processing document or e-mail.

3) Edit the text to make it useful. You likely copied a bunch of text that is not needed. We only care about the package names being installed (blue), so we can erase all the other text:

The following NEW packages will be installed:
  elementary-icon-theme gnome-icon-theme-full leafpad libfm-data
  libfm-gtk-data libfm-gtk1 libfm1 libimlib2 libmenu-cache1 libobrender27
  libobt0 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras
  lubuntu-artwork lubuntu-core lubuntu-default-settings lubuntu-desktop
  lubuntu-icon-theme lxdm lxlauncher lxmenu-data lxpanel lxsession lxterminal
  openbox pcmanfm plymouth-theme-lubuntu-logo plymouth-theme-lubuntu-text
  wvdial
  0 upgraded, 30 newly installed, 0 to remove and 19 not upgraded.
Need to get 16.1 MB of archives.
After this operation, 64.2 MB of additional disk space will be used.
Do you want to continue [Y/n]?  

After removing unnecessary text, you should be left with something like this (actual text will depend on which package you are installing):

  elementary-icon-theme gnome-icon-theme-full leafpad libfm-data
  libfm-gtk-data libfm-gtk1 libfm1 libimlib2 libmenu-cache1 libobrender27
  libobt0 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras
  lubuntu-artwork lubuntu-core lubuntu-default-settings lubuntu-desktop
  lubuntu-icon-theme lxdm lxlauncher lxmenu-data lxpanel lxsession lxterminal
  openbox pcmanfm plymouth-theme-lubuntu-logo plymouth-theme-lubuntu-text
  wvdial

4) Add the following apt-get command to front of the text: sudo apt-get remove --auto-remove . As well, remove any carriage returns from your text – everything MUST on a single line. Your text should now look something like this (actual text will depend on which package you are installing):

sudo apt-get remove --auto-remove elementary-icon-theme gnome-icon-theme-full leafpad libfm-data libfm-gtk-data libfm-gtk1 libfm1 libimlib2 libmenu-cache1 libobrender27 libobt0 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras lubuntu-artwork lubuntu-core lubuntu-default-settings lubuntu-desktop lubuntu-icon-theme lxdm lxlauncher lxmenu-data lxpanel lxsession lxterminal openbox pcmanfm plymouth-theme-lubuntu-logo plymouth-theme-lubuntu-text wvdial

5) Save the document or send the e-mail to yourself, depending on what you used.

If you later decide to uninstall the package, simply open the document, copy the text and paste it into a Terminal. This will completely uninstall the package.

WARNING ! ! !

This should work perfectly if the package you are uninstalling is the LAST package you (or anybody else) installed on your system. In other words: No one has installed anything else – not even updates – since this package was installed!

If other packages have been installed, if updates have been installed, then there is a RISK that those packages or updates may have a dependency on one or more of the packages you are uninstalling.

If you uninstall a package that some other package depends on, then that package will no longer function correctly.

Examining all package dependencies is very complicated. Proceed at your own risk – backups are strongly recommended.

Next page, “Finding Out Which Packages Were Installed”

(page navigation is just under Related posts at the bottom of the page)

6 Comments

  • Mark D. says:

    I used apt-get autoremove to uninstall VirtualBox and it says it can’t locate file. I see it in my directories. But it doesn’t show up in my software center where I installed yesterday. Am I missing something. I don’t want to just remove the dir.

    • admin says:

      I haven’t run VirtualBox inside of Ubuntu (I use it to run Ubuntu inside of Windows), but … the command to remove it should be sudo apt-get remove –auto-remove virtualbox-qt.
      Entering sudo apt-get autoremove instructs the installer system to automatically remove unused packages from the computer.
      Hope this helps and thanks for your question.

  • Sul says:

    aptitude works great for removing those extra dependencies. Also, deborphan can help to find such packages.
    sudo aptitude purge package

    • admin says:

      You can definitely do sudo apt-get autoremove to clean up unused dependencies (which I mention in the article) – and this works fine, but it does not uninstall everything, neither does <>deborphan.
      For example, if you install the Xubuntu desktop, in addition to installing the desktop, it also installs Abiword (among other things). Even if you use the autoremove option of apt-get or you run deborphan, Abiword and all the the applications installed along with Xubuntu desktop do not get uninstalled. Since none of those applications are orphaned (because you can always install them yourself without installing the Xubuntu desktop), the only way to clean them up is to remove them one by one.
      The proper way for the uninstaller to work is to read the installation log to determine what needs to be uninstalled.
      My solution (page 3 of this article) shows the user how to do this manually.
      An even better uninstaller would tell you which applications (if extra applications had been installed) were being removed and give you the choice of keeping the applications you want. On the other hand, a good installer would tell you which extra applications are being installed (apt-get at the commandline does this, but the info is not displayed in the Ubuntu Software Center) and give you the choice of installing them or not.
      Thanks for your comment.

  • Marius says:

    Please, without command line nonsence… Is there any way to uninstall program with GUI?

    • admin says:

      There is no available GUI interface that allows you to completely remove a package and all the other packages installed with it in one step.
      However, you can use Ubuntu Software Center to completely remove all packages – you just have to do it one package at a time.
      (1) determine which packages were installed – this means looking at the history.log to find out which packages were installed.
      (2) enter the package names (one at a time) into the Ubuntu Software Center and click on Remove
      There is an updated (for Ubuntu 12.04)) version of this article here. It is shorter and better expains the problem and solution.
      So far, I have not found any software package (with or without at GUI) that completely uninstall what was installed – they all use sudo apt-get remove --auto-remove <package name> (or its equivalent). As my article explains, in many cases, this leaves behind unneeded and unused packages.
      There are a number of packages that claim to clean up your system, but what they do is run sudo apt-get autoremove which removes some left behind packages. Others also run sudo apt-get purge which cleans out the repository cache (these are the files that are downloaded when you install something), but it does not remove the installed packages.
      This is a serious problem and people should complain about it to Linux developers.