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.
sudo apt-get install $PACKAGE_NAME
dpkg --get-selections [$PACKAGE_PATTERN]
dpkg -l [$PACKAGE_PATTERN]
dpkg -L $PACKAGE_NAME
dpkg -S $FILE
apt-cache depends $PACKAGE_NAME
sudo dpkg --purge $PACKAGE_NAME
sudo apt-get remove --purge $PACKAGE_NAME
sudo apt-get autoremove --purge
Show all automatically or manually installed packages
apt-mark showauto apt-mark showmanual
sudo apt-mark auto $PACKAGE_NAME sudo apt-mark manual $PACKAGE_NAME
Update all packages in the system
sudo apt-get update sudo aptitude safe-upgrade
sudo apt autoremove
Update GRUB configuration
sudo update-grub
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!
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.Thanks Chris!