How to list packages by size using Aptitude

Biggest packages installed on my Ubuntu according to Aptitude
Biggest packages installed on my Ubuntu according to Aptitude

This is a query that I frequently have: how to list packages sorted by their size? I am especially interested in this about installed packages. There are other tools that can do this job, but I like to use Aptitude for this since I use it regularly anyway.

To list all available packages:

$ aptitude search ".*"

Aptitude understands the concept of the install size i.e., how much disk space the files of a package occupy after they are uncompressed and extracted from the package. So, sorting by this installsize is easy:

$ aptitude search ".*" --sort installsize

Note that this listing is in ascending order of size. So, the largest packages are listed at the end.

The problem with this listing is that Aptitude does not display the size, so we have no idea how big the install sizes are. To show that, we can tinker with the display format and get it to display the package name and install size:

$ aptitude search ".*" --display-format "%p %I" --sort installsize

Using the shorter versions of the options, this command becomes:

$ aptitude search ".*" -F "%p %I" -O installsize

Now, to list all installed packages:

$ aptitude search "~i"

Finally, to show the install size of only installed packages and sort by it, we just apply the options shown above:

$ aptitude search "~i" --display-format "%p %I" --sort installsize

Reference: Aptitude user’s manual (its man page is woefully short on details of its commands)

Tried with: Aptitude and Ubuntu 14.04

How to install and uninstall Python package from source

A lot of Python packages are only available as source code.


To install such a Python package, use its file:

$ sudo python install

This will install the Python files to a central location such as /usr/local/lib. If you do not have such permissions or want to install to a user-local location then try this:

  • Create a directory, say /home/joe/python_libs/lib/python in your home directory to host local Python packages.
  • Set the above path in the PYTHONPATH environment variable.
  • Install the package by passing the above path to the --home parameter:
$ python install --home /home/joe/python_libs


To uninstall a package is tricky.

One solution is to find out where the files were installed and then use that list to remove those files:

$ sudo python install --record install-files.txt
$ cat install-files.txt | sudo xargs rm -rf

Another solution is to just locate the installation directory, like /usr/local/lib/python2.7/dist-packages for example and delete the directory of the package.

Tried with: Python 2.7.6 and Ubuntu 14.04

pip cheatsheet

Installing and managing packages of Python is a pain. Many popular Python packages are available for installation from Ubuntu repositories, but they are old versions.

The most convenient way to install, uninstall and manage Python packages is Pip.

  • pip is the usually the Python2 tool. pip3 is the Python3 tool. All the commands in this post will use pip, but they apply the same to pip3.

  • pip and pip3 can be installed from Ubuntu repositories:

$ sudo apt install python-pip python3-pip
  • To install a package from PyPI for all users:
$ sudo pip install foobar

This installs the package files to /usr/local/lib/python2.x/site-packages for pip and to /usr/local/lib/python3.x/site-packages for pip3.

  • To install a package from PyPI for only yourself:
$ pip install --user foobar

This installs the package files to ~/.local/lib/python2.x/site-packages.

  • To uninstall a package that was installed for all users:
$ sudo pip uninstall foobar
  • To uninstall a package that was installed only for you:
$ pip uninstall --user foobar
  • To upgrade an installed package:
$ pip install --upgrade foobar
  • To list all installed packages and their versions:
$ pip list
  • To search PyPI for a package by name:
$ pip search foobar
  • To list the installed file paths of a package:
$ pip show -f foobar

How to view information about a package in Ubuntu

A lot of information about a package can be viewed in Ubuntu. For example, the version, dependencies, description and such.

The most common way to look up information about a package is using apt-cache:

$ apt-cache show screenruler

If you are most familiar with aptitude, the command is similar with that too:

$ aptitude show screenruler

Tried with: Ubuntu 14.04

How to find the repositories which contain a Ubuntu package

If you add a lot of PPA repositories, you might run into a situation where you want to figure out the repository which contains a given package. The madison option of the apt-cache command can be used to list the repositories that contain a given package.

For example, to find the repositories of a package named foo:

$ apt-cache madison foo

Tried with: Ubuntu 12.04 LTS

How to uninstall a package in Ubuntu

Uninstalling a package in Ubuntu can be performed in many ways. For example, assume that the package named vim needs to be uninstalled.

Using the shell

The package vim can be uninstalled using apt-get:

$ sudo apt-get remove vim

Using Synaptic

If Synaptic is not present, install it from Ubuntu repositories using the package name synaptic.

Open it from the Dash with the name Synaptic Package Manager. Search for the package name vim, right-click on its entry in the results, choose Mark for Removal and click Apply.

Using Software Center

Open Ubuntu Software Center from the Dash. Search for the package name vim. When it shows up in the search results, choose it and click Remove.

Tried with: Ubuntu 12.04.2 LTS

How to visualize package dependencies in Ubuntu

Dependency graph of the package of the nano editor.
Dependency graph of the package of the nano editor.

In the Ubuntu package system, a package is dependent on many other packages and there can be other packages that are dependent on it. Thus, the Ubuntu package system is a huge complicated directed graph, with the packages as vertices and dependencies as directed edges.

It would be nice to sometimes to visually see the dependency graph of a package. That is, to see the graph of all packages that a given package is dependent on.

This can be done easily by using debtree. It can be easily installed from the Ubuntu repositories by using the package name debtree.

When invoked with the name of an installed package, it outputs its dependency graph to the standard output in the Dot format. This output can be redirected to a Dot file. I prefer to open this Dot file using Dot viewers like xdot to see the graph visually.

For example, to get the dependency graph of the package of the nano editor and view it:

$ debtree nano >
$ xdot

Thanks to the folks who answered my question on Ask Ubuntu.

Tried with: Ubuntu 12.04 LTS