Section 8.8. Avoid Dependency Hell with apt


8.8. Avoid Dependency Hell with apt

RPM and DEB packages include all of the dependency information that you need. Each package includes headers that list any other RPMs that are required to make it work. I've illustrated one of the problems you might encounter at the start of the previous annoyance.

While the use of yum is limited to RPM-based distributions, apt can be used on distributions based on both the DEB and RPM package-management systems. There are even a number of apt-capable repositories available for Fedora Core and some of the RHEL rebuild distributions.

But to optimize how apt works on your system, you should customize the related /etc/apt/sources.list configuration file, understand different apt commands, and configure a nightly update. For the best way to configure /etc/apt/sources.list, read the "Find the Right Update Repository" annoyance earlier in this chapter. You can mirror your own apt repository based on the related annoyance in Chapter 11.

I personally prefer apt in all situations because it is faster than yum, and there are apt repositories available for Fedora Core, some of the RHEL rebuilds, and SUSE Linux Professional. On the other hand, some believe that yum better fits Red Hat/Fedora Core, as it is written in python. And only yum supports the --exclude switch.


8.8.1. The apt Commands

This section provides the briefest of introductions to the apt commands. They vary somewhat for DEB- and RPM-based distributions. For more information, see the Debian version of this HOWTO at http://www.debian.org/doc/manuals/apt-howto/index.en.html and the apt+rpm HOWTO at http://www.ccl.net/cca/software/UNIX/updating-redhat/apt-howto/.

The apt commands, in my opinion, go into much more depth than yum. However, the Fedora and yum developers are working rapidly to close this gap.

8.8.1.1. apt-cache

With apt-cache, you can search through the repositories that you've configured. A few of the key versions of this command include:


apt-cache search term

You can search through the apt repositories for the search term of your choice. For example, the following command searches through the information for all packages for those related to the MadWiFi project:

 apt-cache search madwifi 


apt-cache show packagename

If you want more information on a specific package, this command can help. For example, if you want to learn more about the madwifi-tools package before installing it, run the following command:

 apt-cache show madwifi-tools 

8.8.1.2. apt-get

Perhaps the key command for handling apt repositories is apt-get. Once you've configured your repositories, the next thing you should do is run the following command, which synchronizes your cache:

 apt-get update 

If you see an error from this command, run it again. It may take a couple of cycles to synchronize the cache. You can then run the commands shown in this annoyance and more:


apt-get install package

You can install the packages of your choice. You need to specify the right package name. If you're not sure, search with the apt-cache search term command described earlier.


apt-get check

This command can help if you have trouble with dependencies. It updates the current cache of packages as well.


apt-get mirror-select

If you've installed the apt commands on Fedora Core, this command can help you select an appropriate repository for your system.

8.8.2. Configuring a Nightly apt Update

You can configure your own cron job for apt updates. If you've read the previous annoyance, you know that there is a standard cron job for yum updates. You can adapt this job for apt.

First, you need to make sure no other script is running dpkg at the same time. That means you need to know the associated lock file that apt creates for your distribution when it is running. For example, when apt is trying to install a package on Debian Linux, it's actually trying to run the dpkg command. In this case, the /var/lib/dpkg/lock file stops others from running dpkg (or apt-get install package, which invokes dpkg) at the same time.

Thus, when you create a cron job for apt, you'll want to make sure there is no current dpkg lock file. The following wrapper in bash makes sure none of the commands within it run unless nobody else is running dpkg on this computer:

 if [ -f /var/lib/dpkg/lock ]; then ... fi 

Within this stanza, you can add the commands you need. As described earlier, it's important to make sure that the current package cache is up-to-date with the following command:

 /usr/bin/apt-get update 

You may want to repeat this command in the cron job, to make sure there are no problems with the update.

Now you can update your system. If you're satisfied with your update repositories and want to download and install all available updates, you could run the following command, which runs in "quiet" mode (-q) and responds to prompts with a yes (-y):

 /usr/bin/apt-get -q -y dist-upgrade 

Putting it all together, you'll have the following cron job:

 #!/bin/sh if [ -f /var/lib/dpkg/lock ]; then     /usr/bin/apt-get update     /usr/bin/apt-get update     /usr/bin/apt-get -q -y dist-upgrade fi 

If you're concerned about specific packages such as the kernel, read about configuring the preferences file in the /etc/apt directory in the following section.

8.8.2.1. Keeping packages in apt

Naturally, you may not want to accept all updates. To keep apt from upgrading everything, you can specify the packages you want to keep in the preferences file in the /etc/apt directory.

The format of /etc/apt/preferences is straightforward. For each package, you'll need three entries: Package, Pin, and Pin-Priority. For example, if you want to make sure that the rsync package is not upgraded, add the following to /etc/apt/preferences:

 Package: rsync Pin: version 2.6.3-2 Pin-Priority: 1001 

You can make sure apt is aware of your restriction in the policy associated with this package, specifically with the following command:

 apt-cache policy rsync 

You can do more with the preferences file; details are beyond the scope of this annoyance. For more information, see the apt HOWTO at http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html.



Linux Annoyances for Geeks
Linux Annoyances for Geeks: Getting the Most Flexible System in the World Just the Way You Want It
ISBN: 0596008015
EAN: 2147483647
Year: 2004
Pages: 144
Authors: Michael Jang

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net