Linux Package Management: Keeping Up with the Times

By: Dee-Ann LeBlanc
Monday, April 22, 2002 10:11:13 AM EST
URL: http://www.linuxplanet.com/linuxplanet/tutorials/4161/1/

Introduction to Package Types

It's easy to just kind of trundle along without giving much thought to how our software changes over the years. We use the same old features version after version unless a new one jumps out at us through a new clickable button, or someone's newsgroup post. The longer you've been working with something, the more you get behind, and I certainly find that's true in my case from time to time.

So, to benefit both myself and my readers, I figured it was time to take a trip down Linux package management lane and see how far we've come from the days of manually placing each tar file so we can extract it to just the right spot.

Some of you might see this material as a little basic, but bear with me, not everyone is as omniscient as you are! I don't claim that the following list is exhaustive, but there are a number of popular package types in the Linux world, and you can recognize them by their filename extensions:

ExtensionDescriptionRelated Commands
.bzBurrows-Wheeler algorithmic compressionbzip2, bunzip2
.gzLempel-Ziv algorithmic compressiongzip, gunzip
.debDebian GNU/Linux package managerdselect, dpkg, apt-get, dpkg-deb, dpkg-split, apt-cdrom, dpkg-ftp, mirror, mirror-master, dpkg-mountable, make-kpkg
.rpmRed Hat Linux package managerrpm, rpmfind, rpmsearch, rpm2html, rpmwatch
.tarFile and directory packagertar .tar.gz or .tgz
Tarballcommon combination of file and directory packaging, and compressiontar, gzip, gunzip
.Z Adaptive Lempel-Ziv algorithmic compressioncompress, uncompress
.zipWindows Zip compatible compressionzip, unzip, zipcloak, zipnote, zipsplit

As you can see, some of the formats are specific to particular Linux distributions, such as .deb and .rpm. Others, such as .gz, .tgz, .tar.gz, and .tar are quite common in the Linux world, and are still used alongside the more complex package managers. Others, such as .Z, .zip, and .bz, are more common in other forms of Unix, or for particular uses such as using .zip to transfer compressed files between operating systems.

Let's take a look at the more commonly-used formats, and then at some of the tools that are lingering in the wings.

Red Hat Package Manager

RPM is the Swiss army knife of the package manager world, in that you use a single command to do a wide variety of things. Well, that's not entirely true: you use a single command, with a whole pile of possible option flags.

At the base of working with RPM files is the rpm command. Some common variations you'll see of using this one include:

Command ExampleDescription
rpm -qa | more
List all installed RPM packages, and of course display them only one screen at a time, there's a lot of them on an RPM-based system!
rpm -ql perl
List all of the files added to the filesystem when I installed the Perl package, and where they were placed.
rpm -qlp perl-5.6.1.i386.rpm
List all of the files and where they will be added to the filesystem if I install the Perl package specified.
rpm -qi perl
Display information about the Perl package I installed.
rpm -qip  perl-5.6.1.i386.rpm
Display information about the Perl package I'm thinking about installing.
rpm -ivh  perl-5.6.1.i386.rpm
Install this Perl package, give verbose output, and display hashes to show me progress.
rpm -Uvh  perl-5.6.1.i386.rpm
Install this Perl package, or if it's already installed but a previous version, update my Perl installation with the new version. Also, give verbose output, and display hashes to show me progress.
rpm -Fvh  perl-5.6.1.i386.rpm
Install this Perl package even if I'm getting errors about conflicts or versions. Also, give verbose output, and display hashes to show me progress.
rpm -e perl
Uninstall the Perl package.

In the old days, it was smart to only install or update one package at a time, since if RPM ran into conflicts trying to install a long list in order, the entire installation or update would fail--this is what caught me up in the KDE installation. Nowadays, the rpm command is a much smarter tool and can figure out the proper order if all of the necessary packages are listed. Even better, if you want to install every RPM in the current directory, just use:

rpm -Uvh *

Popular distributions that utilize RPM are Red Hat, Mandrake, and SuSE. I'm sure I've left someone's favorite out, my apologies in advance. Each of these distributions has at least one tool available that helps you to grab all of the latest security patches, bug fixes, and more for what you've got installed on your system.

Debian Packages

Debian's package management system is a bit more specialized, with a series of commands that together provide the same functions as RPM, and moreso. The key package management components of the Debian system are:

ToolDescription
apt-cdromA shortcut for apt-get when the packages to install are on a CD-ROM.
apt-getDebian package installer where the location to get the files is stored in a specific configuration file, /etc/apt/sources.list.
dpkgThe Swiss army knife of the Debian package management toolset. Use to install, get information about, or uninstall a Debian package.
dpkg-debWork with the contents of a Debian package.
dpkg-ftpA shortcut for dpkg where the packages to install are on a specific FTP site.
dselectA menu-driven nongraphical interface for working with Debian packages.

To accomplish the same things with .deb packages that we did earlier with RPM's, do the following:

Command ExampleDescription
dpkg -l | more
List all installed Debian packages, displaying them one screen at a time.
dpkg -L perl
List all of the files added to the filesystem when I installed the Perl package, and where they were placed.
dpkg-deb --contents perl-5.005_5.005.03-7.1.deb
List all of the files and where they will be added to the filesystem if I install the Perl package specified.
dpkg --info perl
Display information about the Perl package I installed.
dpkg --info perl-5.005_5.005.03-7.1.deb
Display information about the Perl package I'm thinking about installing.
dpkg --install perl-5.005_5.005.03-7.1.deb
Install this Perl package, or upgrade it if it's already installed.
dpkg --force-conflicts perl-5.6.1.i386.deb
Install this Perl package even if I'm getting errors about conflicts or versions. Also, give verbose output, and display hashes to show me progress.
dpkg -r perl
Uninstall the Perl package.

A favorite Debian package management tool is apt-get. This is a wonderfully smart program that lets you do away with those nasty long filenames and also goes out and grabs the item you need for you. First you have to run the apt-setup utility so you've got the apt program properly configured (c'mon, it's not psychic). Once you've done that, you can do cool things like type the following to get the latest list of packages available:

apt-get update

Then you type the following to download any new versions of what you have installed:

apt-get upgrade

To install something you don't already have, it's something like:

apt-get install kde

Mainstream distributions that utilize the Debian package system include Debian (obviously) and SuSE.

Tarballs

The basic package management unit in the Linux world is the tarball (which is in fact still the tool of choice in distributions such as Slackware). I use the term package management loosely here. What sets RPM and DEB apart from a tarball is that a tarball contains just the package and what it needs to function, while an RPM or DEB includes fancy setup widgets, and databased information about the package installed, their components, and more.

A tarball is made up of two separate components. The inner wrapper contains the tar portion of the package, which contains files, directories, the requisite permissions, and more, unless you specified otherwise. A good read through man tar is quite educational. In its basic form, we usually utilize tar in two different ways. Mostly it's to extract the contents of the archive in a format similar to:

tar xvf file.tar

The x is the key, for eXtract, the v gives verbose output and shows you where everything's going, and the f says you're specifying the file name. There are a number of flags you might want to use when creating an archive, but a good basic approach typically involves:

tar cvf file.tar items_to_archive with spaces /in/between

To then compress the archive, since it's probably huge, you just type:

gzip file.tar

The resulting file is file.tar.gz. A great shortcut is:

tar zcvf file.tgz items_to_archive with spaces /in/between

The z compresses the package automatically once it's been created.

Wrapping Up

Yeah, I know, I'm a command-line geek. I do know my way around the GUI too, believe it or not, but there's almost as many cool GUI tools as there are distributions (and they can make your life incredibly easy). So, let's stick to some more fun command-line stuff. Specifically, alien and portage.

Alien (http://kitenet.net/programs/alien) is a package conversion program written in Perl, so you'll have to have Perl installed to use this one. With it, you can take RPM's, Debian packages, SLP's (Stampede Linux packages), and tarballs, and convert the types back and forth as necessary. This is a pretty handy utility if you want to make sure your packages are properly registered in your management scheme of choice. Let me reiterate something listed on the alien web site: "Alien should not be used to replace important system packages." When in doubt, use files built for your specific distribution.

A fun newcomer to the scene is Portage, which is the package management program in Gentoo Linux (www.gentoo.org). I don't single it out amongst RPM and Debian's tool because Portage is far more than a package manager, and doesn't actually require its own file formats. Portage uses a cascading series of configuration files to build (almost) everything from source according to your specifications. Just as in Debian you can type apt-get install kde to upgrade your KDE installation, you can type emerge kde in Gentoo and let Portage do the work: and you get code optimized for your setup as a result.

With the collection of package management tools we have available today in the Linux community, we have the best of all worlds. Through RPM, Deb, SLP, Portage, and I'm sure other variations that I don't know about yet but will soon through reader email, our systems can actually keep track of software dependencies in a way that I haven't really run into in the non-Unix space. But we still have our good old basics as we always will. Sometimes, all you need is a tarball.

Copyright Jupitermedia Corp. All Rights Reserved.