APT is a powerful command-line tool installed from the standard apt package. Although it was developed for Debian systems, versions for RPM-based distributions are available. One such tool is APT4RPM (http://apt4rpm.sourceforge.net). APT for RPM-based distributions poses problems, though, because somebody must maintain the necessary network-accessible databases, and this maintenance is done on an unofficial voluntary basis. The Download Repositories link on the APT4RPM home page provides pointers to these databases.
Once you install APT, you must configure it. The most important APT configuration file is /etc/apt/sources.list, which holds information on the locations APT should search for installation files. Listing 11.1 shows a typical sources.list file. Each line in this file comprises three fields: a type code specifying the types of files to be found at a location; a universal resource identifier (URI), which specifies where the files can be found; and a list of arguments that describe the directories to be searched on the URI.
The first several lines of Listing 11.1 specify CD-ROMs, which are the original installation discs. These discs are identified by name so that APT can determine when you insert the correct disc. The last two lines specify network update sites. In Listing 11.1, both of these sites are websites, but you can also specify FTP sites, SSH servers, or other types of sites. You can obtain a list of official Debian mirror sites that you can list as URIs at http://www.debian.org/mirror/mirrors full. Adding http://security.debian.org to sources.list, as in Listing 11.1, is also a good idea.
Listing 11.1: A Typical sources.list File deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-7 **(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-6 *(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-5 *(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-4 **(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-3 *(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-2 *(20020719)]/ unstable contrib main non-US/contrib non-US/main deb cdrom:[Debian GNU/Linux 3.0 rO _Woody_ - Official powerpc Binary-1 **(20020719)]/ unstable contrib main non-US/contrib non-US/main deb http://security.debian.org/ stable/updates main deb http://http.us.debian.org/debian stable main contrib non-free
You can perform several actions with APT, including:
Database Updates After configuring APT, one of the first actions you should perform is a database update. You can do this by typing apt-get update. The system contacts each of the URIs specified in sources.list to obtain a list of available packages. To be sure the system obtains the latest package available, you should always perform this action before installing or upgrading a package.
Individual Package Installations and Upgrades You can install a new package by passing install and the package name to apt-get. For instance, typing apt-get install nedit installs the nedit package. If the requested package is already installed and a newer version is available, apt-get upgrades to the newer version.
Individual Package Removals You can use the remove keyword to remove a package; for instance, apt-get remove nedit uninstalls the nedit package.
System Upgrades If you want to upgrade all the packages on the computer to the latest version, type apt-get upgrade or apt-get dist-upgrade. These two commands are very similar, but the latter is more intelligent in handling dependencies. In theory, this makes dist-upgrade superior, but in practice it can sometimes break packages. Try upgrade first, and if you run into problems, use dist-upgrade.
Housekeeping Typing apt-get clean removes package files from the /var/cache/apt/archives and /var/cache/apt/archives/partial directories where apt-get puts them prior to installing them. If you use apt-get much, it's important to use this option occasionally, lest your disk fill with original package files.
In addition to these major actions, apt-get supports numerous options. Of particular interest are -f, which attempts to fix broken dependencies on a system; -s, which causes apt-get to report on actions it would take without actually taking those actions; and -y, which enters an automatic yes response to most configuration prompts.
APT can be used in any number of ways. One is in routine package operations; you can use apt-get install to install a package, rather than use dpkg or dselect. A more powerful function relates to system upgrades; typing apt-get update followed by apt-get upgrade or apt-get dist-upgrade will upgrade all your packages to the latest version for your distribution. In principle, you could put these commands in a cron job to execute on a regular basis; however, doing so is a bit risky, because an undesirable automatic update could cause problems. Instead, you might want to use apt-get update; apt-get -s upgrade in a cron job. The result should be a regular report of any updated packages. You can then perform the upgrade at your leisure, at a time when you can cope with any problems that might arise.
Was this article helpful?