Complete, Concrete, Concise

Practical information without the bloat

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.

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.

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:

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.

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:

8 Comments

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.

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).

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.

There is no need to download any sort of CD to remove Ubuntu, you can simply install another operating system (OS) in place of Ubuntu.

Regardless of which OS you choose, it will ask you if you want to reformat the hard disk. You would answer yes and reformat the entire hard disk in order to install the new OS.

The exact steps you would follow would depend on the OS you choose to install. If it is a Linux based OS, then you probably need to choose an advanced installation option and select the entire hard disk.

If it is Windows, I believe, it will prompt you if you want to reformat the entire hard disk.