Home > Computing > Package management on Ubuntu, Linux Mint, Debian, etc.

Package management on Ubuntu, Linux Mint, Debian, etc.

One area in which Linux shines compared to, let’s say, Windows, is how the OS is put together. An entire working Linux distribution is just a set of installed packages. Each file in the system outside of the user’s home directory belongs to some package. There are no mysterious directories containing lots of files of questionable origin and purpose. One can remove any unwanted packages which came pre-installed. In fact one can even install the whole OS from scratch onto a clean drive, package by package, just by installing individual packages.

For years I’ve been using Gentoo Linux, which distributes packages in the source code form, so installing any package involves compiling it from source. The compilation itself is automatic, the user only needs to choose which packages to install, like on any other distribution. When installing Gentoo Linux, one can choose to start from a pre-installed base, or start from scratch and install individual packages one by one, including the kernel, C library and all basic packages.

This approach is great when you want to learn how Linux works and how it is built. Thanks to this, Gentoo Linux is very configurable, since you can choose dependencies and features for every package. I once leveraged this to build fully functional mini Linux OS which occupied 20MB and booted in 3 seconds.

Gentoo Linux comes with a very good package management system. At the core there is the emerge tool, which is used to install and uninstall packages. There is also an optional tool called equery, which can provide various information about the installed packages.

Not long ago I switched my desktop to Linux Mint. Linux Mint is either Debian-based or Ubuntu-based, depending on the flavor. Ubuntu leverages all the tools and structure from Debian, although its packages are often not compatible with Debian.

The immediate problem I faced was how to manage the packages installed on my system. It turns out that on Debian and all derivatives thereof, package management is more complicated than on Gentoo Linux. There are two tools available, which are providing similar functionality. The first one is dpkg, which is the primary package management tool on Debian. Unfortunately dpkg is not that easy to use and has several missing features, so there is another tool called Debian APT, which is in fact a conglomerate of several, separate tools, such as apt-get. On top of that there are graphical tools, such as aptitude or Synaptic, which try to make package management easier, although they are lacking more sophisticated functionality. Overall, package management on Debian feels like an afterthought, the authors of dpkg probably did not intend to address its shortcomings, so other teams kept creating other tools, which have their own shortcomings.

To install new packages I like to use Software Manager on Linux Mint. This is the best graphical package management tool I’ve ever used on Linux. I just type a portion of the name of the package I want to install, and it gives me a list of all packages matching this name, so I click on the one I was looking for and install it. I used Synaptic before on Ubuntu, but Software Manager is easier to use and less confusing.

However, to acquire any kind of information about packages installed on my system, or to uninstall packages, I use command line tools. It’s not because I am used to this approach from Gentoo Linux, there is simply no better way.

Here is how to perform various package management tasks on Debian-derived Linux distributions like Ubuntu or Linux Mint.

Install a package
sudo apt-get install $PACKAGE_NAME
List all installed packages (brief)
dpkg --get-selections [$PACKAGE_PATTERN]
List all installed packages (detailed)
dpkg -l [$PACKAGE_PATTERN]
List files belonging to a package
dpkg -L $PACKAGE_NAME
Determine to which package a file belongs
dpkg -S $FILE
List packages needed/used by a particular package (dependencies)
apt-cache depends $PACKAGE_NAME
Uninstall a package (using dpkg)
Also removes all configuration files.
sudo dpkg --purge $PACKAGE_NAME
Uninstall a package (using APT)
–purge is optional and also removes configuration files
sudo apt-get remove --purge $PACKAGE_NAME
Remove all unneeded automatically installed packages
Once you remove the package you don’t need anymore, some stale dependencies will still remain. You can remove all unneeded packages like this (–purge is optional):
sudo apt-get autoremove --purge

Show all automatically or manually installed packages

When you install packages you want, they are marked as “manual”. But the packages you choose may often require other packages to be installed, the dependencies. These packages, when installed are marked as “auto”.
apt-mark showauto
apt-mark showmanual
Mark a package as automatically or manually installed
Sometimes some packages you really don’t want or need are marked as “manual”, so they cannot be automatically removed. Or the packages you need are marked as “auto”, so they would be automatically removed. You can rectify this with the following commands:
sudo apt-mark auto $PACKAGE_NAME
sudo apt-mark manual $PACKAGE_NAME

Update all packages in the system

Here is the best way to do this, but it requires you to install aptitude:
sudo apt-get update
sudo aptitude safe-upgrade
Unlike apt-get upgrade, this will also update all kernel packages and prepare unneeded older kernel packages for removal. After this finishes, you can remove unneeded old packages:
sudo apt autoremove

Update GRUB configuration

This is not really part of the above, but if you ever need to tweak the boot menu, e.g. to make GRUB remember the last option chosen, then after you edit /etc/default/grub, you need to run this:
sudo update-grub
Opportunities for improvement
I would like to have one tool, instead of a bunch. It would be great to have this kind of functionality in a GUI, but a command line tool would be sufficient. The tool would have to have meaningful commands, which would be much easier to remember, instead of shortcuts, such us dpkg -S which is meaningless.
The tools are also not fully documented. An example from man apt-cache: “For the specific meaning of the remainder of the output it is best to consult the apt source code.” This ridiculous sentence should not be there in the manual. The result of confusing and missing functionality as well as incomplete documentation is lots of users wandering on forums looking for answers to simple questions.
Hopefully the above post will help you.
Categories: Computing
  1. Bruce Wehr
    7.08.2014 at 11:16

    Hi – I’m a new Linux Mint user, and I found this article very useful – thanks! I found it while googling for a particular aspect of package management that, unfortunately, it failed to answer: I’m interested in getting the version of an installed package. Do you know how this can be done?

    Thanks again!

    • 7.08.2014 at 12:45

      Hi Bruce! I’m glad you found it useful. To get status of a package run: dpkg -s $PACKAGE_NAME. This will tell you whether the package is installed and the installed version.

  2. Bruce Wehr
    7.08.2014 at 13:01

    Thanks Chris!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: