The Basics of Debian Package Management: APT and Repositories [Linux 101]

One of the foundations of the Debian package management system is the DEB package format, which contains information on where the package should be installed and what other software it needs to function. But this is only half the story… the other half is the Advanced Packaging Tool, or APT. It’s actually a set of tools that work with dpkg, the installer for DEB packages, to easily keep your system up to date.

APT Repositories

The ease with which you can update your system first depends on repositories of files in an APT-readable format. These repositories are nothing more than directories that contain the following two files:

  • Packages.gz: This is a list of all the installable binary packages in the repository. If you have some packages (maybe even some you packaged yourself with Debreate) in a directory, you can generate this file automatically with the “dpkg-scanpackages” command. Note that the resulting file is Gzipped.
  • Sources.gz: This is a list of all the installable and buildable source files in Debian format. The command “dpkg-scansources” can generate this file. Note that source packages can be built automatically.

Once some packages live in a repository with a Packages.gz or Sources.gz index file, a user just needs to configure the file “/etc/apt/sources.list” to read those indexes and build a list of the packages available in all repositories. Configuring “sources.list” is as easy as adding lines to it in the following format:

Each of the above items should be separated by a single space. The meanings of each of these is as follows:

  • package type“: The line should begin with either “deb” (to install the binary packages from the repository) or “deb-src” (to install source packages from the repository).
  • package location“: This should be a URI where the repository is located.
  • distribution name“: The “distribution” of a Debian-based OS is the equivalent of a release. For example, Ubuntu’s latest release uses the distribution name “quantal,” while repositories for the latest from Linux Mint require “nadia.”
  • component name“: This also depends on the distribution, but most will separate their packages into components. For Ubuntu, these are “main” (free and supported software), “restricted” (non-free but supported software), universe (free, unsupported software), and “multiverse” (non-free, unsupported software). There are sometimes other components, such as “partner” in Ubuntu for software developed by Canonical’s partners. Note that more than one component can be listed on a single line in “sources.list“.

Once a line (or lines) like the above are added to the “sources.list” file (either with a text editor, or through a tool like the Software Centre), updating the package lists will take the following steps:

  1. Go to each of the “package locations” in the “sources.list” file;
  2. Drill down into the “distribution” for that locations;
  3. Go into each of the “components” specified, and;
  4. Download either Packages.gz (if “deb” is selected for the package type) or Sources.gz (if the line starts with deb-src).

APT Tools

The command to perform the update referenced above should look familiar:

The “apt-get” program is part of the APT collection of tools to perform actions on package. The most crucial commands you’ll need to remember are variations on “apt-get” (This one is the most important. Learn how to use it. Seriously.) and “apt-cache” (Many of the “apt-get” commands I run are immediately preceded by “apt-cache”). Some of the common sub-commands you’ll require for these are (you should run all of these as root using sudo):

  • apt-get update: Updating the package lists, as described above
  • apt-get upgrade: Installing the latest package of any software for which there is a newer version listed in the index file
  • apt-get install [package name]: This will download and install the package specified, as well as install any other required software for that package
  • apt-get remove [package name]: Using the “remove” sub-command will uninstall a package, but retain any configuration files it may have created. If you’d like to get rid of those as well, use “apt-get purge“.
  • apt-cache search [search term]: This command will list packages whose name or description contains the entered search term.
  • apt-cache show [package name]: This command will display information on the specified package.

Some further reading is available on Ubuntu packaging and repositories for those who want to get a little more involved, and perhaps even contribute by packaging and maintaining your favorite application.

Aaron Peters

Aaron is an interactive business analyst, information architect, and project manager who has been using Linux since the days of Caldera. A KDE and Android fanboy, he'll sit down and install anything at any time, just to see if he can make it work. He has a special interest in integration of Linux desktops with other systems, such as Android, small business applications and webapps, and even paper.

One comment

Comments are closed.