Ubuntu 12.04 – How to Completely Uninstall/Remove a Package/Software/Program

This tutorial shows how to completely remove or uninstall a package in Ubuntu 12.04. These instructions should work for other versions of Ubuntu, it’s derivatives (Edubuntu, Kubuntu, Lubuntu, Xubuntu, Ubuntu Studio) and other Debian based Linux distributions – but no guarantee is made.

This tutorial is definitely on the advanced rather than basic side of things, but if you are careful, it shouldn’t be a problem.

WARNING ! ! !

There is a small but real risk of data loss or making other programs or Ubuntu unusable.

It is advisable to ensure you have a backup before proceeding.

I am somewhat over emphasizing the risk, but anything can happen – there might be a power failure in the middle of uninstalling and this might leave your system in a funky state, or you might select a critical system file for deletion and this leaves your system unusable.

I don’t expect anything bad to happen, but I make no guarantees.

You can jump directly to the How To part here.

You would think that uninstalling a package would be as easy and straightforward as installing it – either enter sudo apt-get remove --auto-remove <package name> at a command line or click Remove in the Ubuntu Software Center. Unfortunately, it is not.

The Problem

There are three types of packages: (1) simple, (2) with dependencies, (3) complicated.

Simple packages just install the program and that’s it. They are completely self contained and don’t depend on anything other than the core operating system being present. These types of packages are rare.

stella (an Atari 2600 emulator) is an example of a package that depends only on the core operating system files.

Packages with dependencies require other packages in order to work. When one of these packages is installed, the Ubuntu Software Center or apt-get figure out which other packages are needed and automatically install them for you. Unfortunately, when you uninstall the original package, these extra packages are usually left behind. Sometimes you can clean them up by using the command sudo apt-get autoremove, but that is the exception rather than the rule.

stellarium (a 3D planetarium / sky simulator) is an example of a package that requires an additional package (stellarium-data) to be installed in order to work. When you uninstall it, it leaves behind stellarium-data. The good news is that stellarium-data can be uninstalled using sudo apt-get autoremove.

abiword (a word processor) is an example of a package that requires additional packages (about 16) to be installed . One of those packages is ttf-lyx (a font). When you uninstall, abiword it will automatically uninstall some packages, the remainder can be removed using sudo apt-get autoremove, but the package ttf-lyx will not be removed unless you explicitly remove it.

Complicated packages (also called metapackages) install the package requested and any dependencies, and they also install additional packages that are not at all related to the original package. These are the hardest to clean up, since you have to uninstall each additional package (along with its dependencies) separately.

lubuntu-desktop (a desktop environment based on the lxde interface) is an example of a package that installs several dependency packages and several additional packages (about 189). When you uninstall it, it only removes lubuntu-desktop (about 30kB). Even sudo apt-get autoremove will remove nothing else – all those extra files and packages remain on your system (about 321MB). The 30kB and 321MB are not typos, uninstalling lubuntu-desktop leaves behind about 99.99% of everything it installed.

These include packages like abiword, leafpad (a text editor), lubuntu-core, lxde-common, along with many, many other packages.

Not only are various packages left behind after an uninstall, but also configuration data used by the removed package, directories (folders) and user data – all of these have to be manually removed.

Why Can’t Everything be Uninstalled?

My best guess is because it is a low priority:

  • Users want applications to install easily and work. In the (fairly distant) past, installing applications in Linux was a pain – users would install an application and it wouldn’t work, then they would discover they needed to install some other package to get it working, and then there were package incompatibilities (still a problem in Linuxland) and so on. Various Linux distributions do a very good job in packaging applications for easy installation.

  • Hard disks are big. If you have a 500GB hard disk, will you really notice if 3MB or 50MB or even 1GB of data are cluttering it up? Probably not, your Internet browser’s web cache is probably bigger.

  • It is not sexy. Who cares if a programmer wrote a really neat uninstaller? Probably no one. Programmers are more interested in “cool” apps. And since it is possible to manually uninstall all the unnecessary applications, there is no incentive to write a proper uninstaller.

  • Uninstallation should be a “rare” activity. Although, I think users are very likely to want to try out applications and uninstall them if they don’t like them or find it is not what they wanted.

  • Finally, if the uninstaller breaks an application the user wants to keep, the user is going to be unhappy, so it is better to be very conservative when uninstalling.

All the information needed to uninstall an installed package is readily available. The only information not readily available is which files and folders are created by an application – so cleaning up all the config data, application folders and user data is harder.

This is a long standing problem with Linux and many projects have been started (and abandoned) for cleaning up leftover files on the computer.

How to Completely Remove a Package

Quick Instructions

1) Open the aptitude log file (/var/log/apt/history.log).

2) Locate the files that were installed.

3) Remove the files using sudo apt-get remove --auto-remove <file names>

NOTE: it is a good idea to ensure that you are not removing any extra files. This might happen if you (or someone else) has installed other packages or updates.

4) Locate and remove configuration files and data associated with the package. Most often, they will be found in /home/ and /home/.config/ directories.

Detailed Instructions

Finding Out Which Packages Were Installed

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

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

Instructions for openning a terminal can be found here.

Opening the Installation History Log File

All installation and uninstallation operations that happen using apt-get or Ubuntu Software Center (or any of the aptitude family of functions) are stored in /var/log/apt/history.log. Examining the contents of this file allows us to determine which packages were installed.

1) Click on the Home Folder icon:

2) Click on File System:

3) Double-click on the var folder:

4) Double-click on the log folder:

5) Double-click on the apt folder:

6) Double-click on the history.log file – this should open it with gedit, the default text editor in Ubuntu 12.04:

A Quick Overview of the history.log File

The history.log file contains all the operations performed on your system using apt-get (or any of the aptitude family of programs)

Each block of operations (yellow) contains:

  • a Start-Date and End-Date (red) for the operation
  • the operation performed (blue)
  • additional information about the operation (green)

In our case, we are interested in the Install information.

Finding the Installation Data

7) Search for the package you installed. If it was the last package you installed, then it will be at the end of the file. The records are stored with the newest operations towards the end (bottom) of the file and the oldest at the beginning (top) of the file:

In the sample below, you can see I installed lubuntu-desktop on 16-May-2012:

Start-Date: 2012-05-16 04:23:17
Commandline: apt-get install lubuntu-desktop
Install: libopenal1:i386 (1.13-2, automatic), libxfcegui4-4:i386 (4.8.1-5, automatic), chromium-browser-l10n:i386 (14.0.835.202~r103287-0ubuntu1, automatic), libobrender27:i386 (3.5.0-0ubuntu3, automatic), lxsession:i386 (0.4.6.1-1, automatic), libts-0.0-0:i386 (1.0-9, automatic), libswscale2:i386 (0.7.2-1ubuntu1, automatic), chromium-codecs-ffmpeg:i386 (14.0.835.202~r103287-0ubuntu1, automatic), libavutil51:i386 (0.7.2-1ubuntu1, automatic), libhttp-daemon-perl:i386 (6.00-1, automatic), and, many, many others ...
End-Date: 2011-11-01 04:34:04

8) Cut and paste the Install data into an editor. You can start a new document in gedit by clicking on the Create a new document icon:

9) Edit the data to be to remove all unnecessary text.

The data has the following form: <package name>:i386 (something in parentheses),

Only the package name is important. The :i386 (something in parentheses), needs to be deleted.

So libopenal1:i386 (1.13-2, automatic) becomes libopenal1 after removing the extra information.

If you have a lot of text to edit (as in this example), you might consider using a text editor that offers regular expression matching – like LibreOffice Writer – for search and replace.

Using LibreOffice Writer 3.5, you can use the following regular expression (I think it is complete, but it might miss the odd expression):

Use this if you are running the i386 version of Ubuntu:

:i386 \([0-9\~\.\+a-zA-Z\-, ]*\),?

Use this if you are running the amd64 version of Ubuntu:

:amd64 \([0-9\~\.\+a-zA-Z\-, ]*\),?

This regular expression is slightly different from the one I used in the 11.10 version of this article. LibreOffice has made some changes to the way it parses regular expressions since version 3.4. It has also changed the default shortcut key for bringing up the Find and Replace dialog from Ctrl+Alt+F to Ctrl+H.

Press Ctrl + H to launch the Find and Replace dialog in LibreOffice Writer.

  1. Click on the More Options button (it will change to Fewer Options).
  2. Click on the Regular expressions box.
  3. Enter the regular expression into the Search for field.
  4. Click on the Replace All button.

10) Add the following at the start of the edited package list: sudo apt-get remove --auto-remove

11) Cut and paste this package list with the apt-get command from step 10 into a Terminal to completely uninstall the package.

To paste into a terminal, you need to right-click in the terminal and select the Paste option from the popup menu. Using the traditional shortcut Ctrl+V will not work.

Detailed instructions on how to open a terminal can be found here.

It should look something like this (the exact list of files will depend on what you are uninstalling):

12) Press the Enter key and enter your password (this is your login password):

NOTE: when you type your password, nothing will happen on the screen. This is normal. As a security feature, Linux does not echo back any indication of the characters you are typing in.

NOTE: You will only be asked for your password if this is the first time in this terminal session that you are using sudo apt-get.

13) Press the Enter key after entering your password and apt-get will respond by showing which files are going to be uninstalled:

If you want to uninstall the files, then press the Enter key. If you don’t want to uninstall the files, type the N key and then press the Enter key.

NOTE: if this was not the last package installed. Or if updates have been installed, it is STRONGLY advised that you double-check the files being uninstalled to ensure they do not include any extra files.

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.

Double Checking Your Uninstall Script

If the package you are uninstalling is not the last package to be installed, there is the risk that you will accidentally uninstall a package that some other application depends on.

Why Double Check?

For example, you install abiword. Abiword depends on the package ttf-lyx and it will be installed it if it is not already installed.

Later, you install cadabra. Cadabra also depends on ttf-lyx, but since it is already installed, it will use the installed copy instead of installing a new copy.

If you uninstall abiword using the technique above, it will explicitly uninstall ttf-lyx (which is also needed by cadabra – which was installed after abiword).

This will cause apt-get to uninstall cadabra because cadabra depends on ttf-lyx.

To avoid this problem, it is necessary to double check that you are not removing any extra files.

Since apt-get displays the files it is going to uninstall, it is a simple matter of checking that no additional files were added to the uninstallation:

Uninstalling Configuration Data

I don’t recommend doing this unless you know exactly what you are looking to delete.

The last thing left to do is to delete / remove all the configuration data.

Unfortunately, this is hard to do since there is no record of what files and folders the (now uninstalled) application put on your computer.

A good place to start is in your /home directory and your /home/.config/ directory.

However, data, files, and folders could be squirreled away all over the place.

As you can see from these screenshots, it is not necessarily obvious what folders and files need deleting:



6 Comments

  • Mikle says:

    Thank you for the arcticle. The information was useful for me. I was looking for information about history of installed packages and found this article. Now I understand details. And I didn’t know that Libre Writer can work with regex.

    • admin says:

      Thanks for the comment.
      In addition to the history.log file, you may also have several history.log.<number>.gz files. Periodically, aptitude will start a new history.log file and gzip the old one. I am not sure what triggers this, but I think it is a software update.
      If you can’t find what you are looking for in the history.log file, then it might be in one of the gzipped files.
      Yes, Libre Writer does work with regex, unfortunately, it has changed the regex behaviour between version 3.4 and 3.5 (mind you, my original regex expression was probably buggy and Libre Office has just tightened up the regex handling).

  • GordonO says:

    I am very impressed with your web-site and all its offerings. You explain things extremely well and I thank you sincerely for the great deal of time and effort you obviously put into your articles.

    • admin says:

      Thank you very much for your positive comment!
      Yes, I do put a lot of time into each article – sometimes I wonder if all the effort is worth it, but each positive comment tells me that it is.

  • kran says:

    Thank you very much for your article
    I am a newby for ubuntu
    from this time I must be carefully to uninstall any packages
    because my regularly use “autoremove” which a big risk!

    • admin says:

      I’m glad it was of use to you.
      Yeah, uninstalling software is a bit tricky in Linux. They have come a long way in making software easy to install, but they still have a long way to go to make it easy to uninstall.
      It is ironic but one of the common complaints about Windows is that the OS slowly gets bloated with unneeded files – but exactly the same thing happens in Linux. In fact, I would say the problem is worse under Linux.
      Thanks for your comment.