Using APT on RPM-Based Systems

Managing packages can be a tricky undertaking, even with package tools like the RPM Package Manager (RPM), the package management tool used by Conectiva, Fedora, Mandrake, Red Hat, SuSE, Yellow Dog, and many other distributions. With RPM, you may try to install a package, only to find that it depends on others you don't have. Or, you might discover that your packages are several versions out of date and then have to track down and install potentially dozens of updates to fix security and other problems with the old packages.

Managing packages can be a tricky undertaking, even with package tools like the RPM Package Manager (RPM), the package management tool used by Conectiva, Fedora, Mandrake, Red Hat, SuSE, Yellow Dog, and many other distributions. With RPM, you may try to install a package, only to find that it depends on others you don’t have. Or, you might discover that your packages are several versions out of date and then have to track down and install potentially dozens of updates to fix security and other problems with the old packages.

The Debian distribution has long had a solution to these problems: the Advanced Package Tools (APT), a set of programs that help manage packages. APT lies at a layer above Debian’s usual lower-level package management tools, such as dpkg (Debian’s equivalent to rpm). By linking to one or more package repositories, APT can streamline software installation, upgrades, and other management operations.

Although APT was developed for Debian, it’s been ported to work with RPM-based distributions. The result is that most RPM-based systems can take full advantage of APT’s features, which can be very useful on any Linux system.

Why Use APT on an RPM-Based Distribution?

Many RPM-based Linux distributions today ship with package management tools that provide features similar to APT. For instance, Fedora and Red Hat’s Package Management and Update Agent tools and SuSE’s YaST and YaST2 let you install sets of packages, with all dependencies met, and even provide the means to update your system software to the latest versions with just a few button clicks.

Why, then, should you use APT? In some cases, APT provides few benefits over more distribution-centric tools. However, APT does have some key advantages:

* DISTRIBUTION NEUTRALITY. Because APT works with both Debian and the most popular RPM-based distributions, you can learn one tool and use it on many distributions. This is useful if your site hosts machines with different distributions or if you switch from one distribution to another.

* COMMAND-LINE TOOLS. Most of the distribution-specific tools use GUI interfaces. That can be handy sometimes, but it can also be limiting. For instance, you may not be able to schedule an automatic update via cron. (To be sure, blindly running an update via cron can be risky, but with APT, you can schedule a daily check for new packages to be e-mailed to you, so that you can be quickly informed of available updates.) Text-mode tools can also be easier to use remotely — say, to perform a system update on an office system via an SSH login when you’re travelling. Having said that, a GUI front-end to APT is available, as described later in this column.

* DATABASE SELECTION. APT implementations for RPM let you point to third-party package sites. This means that you might be able to obtain updates even after your vendor has dropped support, and you need not register to obtain updates.

Of course, this can also be a source of problems. For instance, you’re at the mercy of whoever maintains your package database. With APT, though, you do have the ability to easily change or add databases, even including databases for obscure programs that aren’t part of the official distribution, if the programs’ authors provide the necessary APT hooks.

* EASE OF USE. Even without a GUI, APT can be very easy to use once you’ve configured it and once you’ve learned a handful of commands. With just a little practice, you’ll probably find APT is easier to use than some GUI package maintenance tools.

Of course, APT isn’t for everybody. If you’re already using your distribution’s package update and installation system and don’t have any problems with it, you might not want to bother with APT. Or, consider it a tool to try out when you’ve got nothing more pressing to do. If APT sounds appealing, though, read on…

Obtaining and Installing APT for RPM

The main port of APT for RPM systems is headquartered at http://apt4rpm.sourceforge.net. The site provides a download page with links to sites that host the APT software for RPM. You may also want to check http://apt.freshrpms.net, which hosts versions of APT that are preconfigured in sensible ways for certain distributions.

When browsing, look for the APT client package called apt. (The APT server software, named apt4rpm, is run on servers that deliver files to APT clients. It maintains the necessary indexes for clients. You might run such software if you want to maintain a local APT repository for a network full of clients.)

You should be able to use the same APT client package on any RPM-based Linux distribution, with one caveat: the package may have dependencies upon libraries, versions of RPM, and so on that may or may not be installed on your system.

You can install APT for RPM just as you would install any other RPM package, using the rpm command:

# rpm -Uvh apt-0.5.4cnc9-1cl.i386.rpm

Of course, the package does have its own dependencies, so it’s possible you’ll need to track down and install additional packages. However, it may be the last time you do such busy work, because installing the right pieces is one of the things APT does for you — at least, within the limits of the software available at the repositories you use.

Configuring APT for RPM

Once the APT software is installed, you must configure it. This is done via a file called /etc/apt/sources.list, which, as you might guess, contains a list of software sources. Each line in this file is either a comment (a line that begins with a hash mark, or #) or a line that defines a single APT repository. The repository definitions look like this:

rpm ftp://ftp.gwdg.de/pub/linux/suse/apt
SuSE/9.1-i386 update security base

(This line has been split across two lines in print, but is a single line in the sources.list file.) It consists of three parts:

* TYPE. This item is a code that defines the type of packages held in the repository. In an APT for RPM system, the type code will almost always be rpm, but a type of rpm-src defines a source site, from which source RPMs can be downloaded. On Debian or derivative distributions, the type code will be deb or deb-src.

* URI. The second item is a Universal Resource Identifier (URI) that tells APT where to look to find the archive site’s database. Typically, the URI points to an FTP or HTTP (web) site. (You can also create a URI to point to a local CD-ROM; however, this requires CD-ROMs that contain APT index files. Most RPM-based Linux distributions lack these files, so you’ll need to create them specially if you want to use this option.) If you’ve got a fast Internet connection, it’s almost certainly more convenient to point directly to FTP or web sites.

* ARGUMENTS. Everything after the URI is arguments. The first argument (SuSE/9.1-i386 in this example) is a distribution code that prevents the system from installing inappropriate packages (say, Fedora RPMs on a SuSE system). The remaining arguments (update security base in this example) are descriptions of the types of packages that you want APT to manage. The base code stands for the base OS packages, while update and security stand for normal and security-related updates. Some sites provide other codes; they’re arbitrary and ultimately refer to subdirectories on the package site.

The big question, of course, is what site or sites to use for your configuration. The APT web sites (both http://apt4rpm.sourceforge.net and http://apt.freshrpms.net) provide sample configurations for various distributions. If your distribution is one that’s listed on one of these sites, your best bet is to copy the sample sources.list file. Alternatively, you can do a web search on your distribution’s name and “APT.”

With luck, this should turn up a sample configuration. Do not attempt to use a configuration for any distribution except the one you’re actually using! Even related distributions, such as Fedora and Mandrake, have enough differences that you could render your system unusable if you point it to the wrong archive site.

Some software packages provide APT configuration lines that you can add to your sources.list file if the package isn’t included with your distribution. This can be a very handy way to keep your system up to date with changes in such packages. To use multiple archive sites, such as the main one for your distribution and another for a package you want to use, simply place each on its own line in sources.list. APT checks the sources in sequence, so if they overlap in the packages they provide, place the more reliable or faster site first.

Using APT for RPM

The main text-mode tool for using APT is apt-get, a command-line program that accepts various parameters to perform common actions. A similar, interactive text-mode program is called apt-shell. Use the latter if you want to perform several APT actions.

Common apt-get commands include:

* update. This command updates the APT package database. It should be the first command you issue after installing APT. You should also run this command periodically to ensure that APT’s database remains up-to-date. This is vital to maintaining a secure system: if you don’t update the database, APT won’t be able to install any critical security updates that might be issued for your distribution.

* upgrade. Use this command to have APT upgrade your packages to the latest versions. This command doesn’t install new packages or remove existing ones.

* dist-upgrade. This command works much like upgrade, but removes packages that are no longer required and installs necessary new dependencies, which makes it more reliable if an upgraded package has changed dependencies.

* install package. You can install a new, named package and its dependencies with this command. Package names are the package names only, not full filenames.

* remove package. remove deletes a package from your system. It’s similar in practice to typing rpm -e package.

* source package. You can quickly retrieve a source package with this command. You can then rebuild the source package locally, if you prefer that.

* clean. APT downloads packages into /var/cache/apt/ archives/ and leaves them there. Over time, this accumulates files in this directory, which can rob your system of disk space. The clean command cleans RPM files out of this directory. Running it periodically, or after a major system upgrade, is worthwhile.

Typically, after installing APT, you’ll run a couple of commands:

# apt-get update
# apt-get dist-upgrade

These two commands, taken together, bring your system up to date with the latest versions of all software packages. If you want to see what the latter command will do without actually committing to make the changes, you can use the -s parameter:

# apt-get -s dist-upgrade

The result describes the options that APT would have taken had the -s parameter been omitted. You may want to perform an apt-get update followed by this simulated upgrade operation on a daily or weekly basis via a cron job. On most systems, the result should be an e-mail sent to you with the output of the commands, which should keep you informed of potentially worthwhile available upgrades.

Using Synaptic

While APT is not a GUI tool, a GUI front-end to APT is available: synaptic. To use it, type synaptic in an xterm or similar window. synaptic is shown in Figure One, running on a Fedora system.

Figure One: Synaptic provides a friendly GUI front-end to APT

Of course, you must first install synaptic. The easiest way to do this is to use APT’s text-mode tools. Just type apt- get install synaptic. (This command works on some systems, but unfortunately, synaptic isn’t available in all distributions’ APT archives. If you run into this problem, you’ll have to track down synaptic in some other way, such as searching http://www.freshrpms.net or http://www.rpmfind.net.)

Once synaptic is running, just point-and-click. Packages are grouped in expandable categories — click the triangle to the left of a category name to see all of the packages in that category. Those that are installed have dark squares to the left; uninstalled packages’ squares are light gray. Click an application you want to install or remove, and click the Install or Remove buttons, respectively. This action only marks the package to be added or deleted, though; to actually implement the changes, you must click Apply.

You can use synaptic for additional management tasks, too. For instance, clicking Refresh is equivalent to typing apt-get update, and clicking Upgrade System upgrades all of your installed packages, much like apt-get upgrade or apt-get dist-upgrade (a dialog box asks you whether or not you want to perform a “smart” upgrade, equivalent to dist-upgrade).

After you choose most actions, synaptic asks you to confirm your choice. This lets you review your changes to avoid errors, such as upgrading to a package that you know won’t work.

synaptic is most useful in locating packages, because it includes a search function. This is a wonderful feature if you want to install a package but can’t remember its exact name — for instance, if a package might be broken into client and server parts or have a separate documentation package.

All things considered, APT is a very useful tool for managing packages on Linux systems. The port of APT to RPM makes APT one of the most broadly-applicable package management tools, as it can work with both Debian- and RPM-based systems. Thus, learning to use APT can help you administer almost any Linux system.

Roderick W. Smith is the author or co-author of twelve books, including Linux Power Tools and Advanced Linux Networking. He can be reached at rodsmith@rodsbooks.com.

Comments are closed.