Linux Package Manager Cheatsheet

Keeping Your Linux PC In Fine Tune

October 2, 2008

By
Carla Schroder

LinuxPlanet Classics

In these modern times of Linux glitz, and yes, even bling (shudder) we crusty old command-line commandos sometimes like to put down our stewed prunes, ascend the podium, and remind our newer Linux compadres that underneath the tinsel and glitter lies the all-powerful command line. On good days, when our arthritis isn't flaring up too badly, we'll even emit a bit or two of usefulness. As it happens, all the stars briefly aligned in exactly the correct sequence and thus I was inspired to assemble this Fedora and Debian cheat-sheet, starring Yum, RPM, aptitude, dpkg, and apt-file.

Graphical package-management tools are nice, and everyone who is anyone has their favorites. But gnarly system administrators running headless boxes, users who want more speed and options, and anyone who is struggling with a broken X.org installation need to know command-line package management.

Gentoo and Slackware have their own package managers, and source installs are the closest thing to a universal installation package there is. Fedora and Debian represent the majority of the Linux universe. Fedora, Red Hat, CentOS, Lineox, White Box Linux, and several others use Yum. Debian's children are many: Ubuntu, Knoppix, Linspire, Mepis to name a few. So for today we shall focus on Fedora and Debian and all of their relatives.

Yum
If you like, go ahead and take a moment to rant at the astonishing numbers of persons who still complain about "RPM hell" as though Yum were never invented. RPM is package manager that concerns itself only with single software packages and how they are put together, and does not care about dependencies. Yum is dependency-resolving installer for RPM. You should use Yum for installing and removing packages as much as possible, and RPM for collecting information on packages. This is the path to happiness.

By default, Yum queries your remote repositories every single time you run it, which are listed in /etc/yum.repos.d. This can get boring pretty quickly because it takes time to download fresh package lists. An alternative is to create a local Yum cache. To do this, add this line to /etc/yum.conf:

keepcache=1

Then run yum -C 'options' when you want to hit the local cache instead of fetching fresh data.

RPM
RPM is usually faster than Yum when you're trying to find out what's what, like "is a package installed on your system":

$ rpm -q 'foo'

Or to list all the files in an installed package:

$ rpm -ql 'foo'

What package does this file belong to?

$ rpm -qf '/usr/bin/foo'

List all installed packages and save the list in a file:

$ rpm -qa 'foo' | tee rpmlist.txt

Aptitude
Aptitude is the new dependency-resolving installer for Debian. Well, not all that new, but it's newer than our old favorite apt-get. Aptitude works harder than apt-get, which means you work less hard. One of its most appealing features is when you remove a package, it also removes any unneeded dependencies that were installed with it. Aptitude uses pretty much the same commands as apt-get. It's not a good idea to use both- either use aptitude or apt-get exclusively, or your dependencies will get confused.

These commands install or upgrade a package (yes, use the same command for both), reinstall a package, remove a package, or remove a package and all of its configuration files:

Let's take a closer look at these three commands. You want to run aptitude update often so you always have the latest package lists.

Once of Debian's strongest features is its infinite upgrade-ability- you only need to install it once, then forever after all you do is upgrade or dist-upgrade it. Upgrade and dist-upgrade are two different things. Upgrade means bringing your current release up-to-date. Suppose you're running Debian Stable, version 3.1, which is currently code-named Sarge. You'll run aptitude upgrade to keep it current with security and bugfixes. You won't be getting major new software releases, because those go into the newer Debian releases, Testing and Unstable, codenamed Etch and Sid.

What if Sarge becomes too old and moldy for you, and you want to live on the bleeding edge with Etch or Sid? Or maybe when Etch is released as the new Stable Debian, you'll want to upgrade to it. When the time comes you'll edit your /etc/apt/sources.list to point to the new repositories, then run those three commands in order. With a bit of luck you'll have a shiny new upgraded system with minimal effort.

Aptitude displays package information on installed packages:

$ aptitude show 'fie'

And finds packages to install:

$ aptitude search 'fie'

dpkg
dpkg is rather like RPM, because it operates on individual packages without tracking dependencies. Also like RPM, it's fast for getting information. These commands look to see if a package is installed on the system and list all the files in a package: