Debian has more or less all free software in the known world!
One of the things that has made Debian famous among Linux distributions is the APT package management system. Its ability to handle often complex chains of interdependencies between packages makes installing software very convenient. APT selects Debian software packages, commonly known as debs, from one or more archive sources.
Using APT is the most important skill for a Debian administrator to learn. The two most popular tools in Debian for managing packages are
aptitude. Most people find
aptitude superior, as it not only includes all of
apt-get's features, but also includes many others, such as an interactive menu-driven mode and the removal of packages when you no longer need them.
By following this article, you'll learn the basics of package management on Debian using the
The software available in the Debian Linux distribution is organized into packages. Packages consist of precompiled software and additional files that integrate the software into the Debian system. Adding software to your Debian system is usually a matter of installing packages.
After you ran the Debian installer, several packages were installed for you. Now you can start adding further packages using
aptitude install. This article shows how to install the
sudo package, which enables normal users to do tasks as the system superuser. (See my article Using the Root Account on Debian for more information on running commands as root.)
To install software, you must be running as the root, the superuser account. Until you have
sudo installed, you need to log in to the console as root, or become root by running
su - and typing in the root password.
# aptitude install sudo Reading Package Lists... Building Dependency Tree... Reading extended state information... Initializing package states... Reading task descriptions... Done The following NEW packages will be installed: sudo 0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 147kB of archives. After unpacking 369kB will be used. Writing extended state information... Done Get:1 http://ftp.uk.debian.org testing/main sudo 1.6.7p5-2 [147kB] Fetched 147kB in 2s (55.2kB/s) Selecting previously deselected package sudo. (Reading database ... 25786 files and directories currently installed.) Unpacking sudo (from .../sudo_1.6.7p5-2_i386.deb) ... Setting up sudo (1.6.7p5-2) ... No /etc/sudoers found... creating one for you. Reading Package Lists... Done Building Dependency Tree Reading extended state information Initializing package states... Done Reading task descriptions... Done
The installation process prints a lot of text, most of which you can ignore. You'll often find useful information, however, after the
Setting up line. In this case, the
sudo package installation process says that it's created a configuration file /etc/sudoers.
You can see that the
sudo software is now installed by looking in /usr/share/doc/sudo, the usual place for accompanying documentation. Note also that the configuration file, /etc/sudoers, is in place.
Removing software is as easy as running
aptitude remove. Remove the
sudo package and observe how the system changes:
# aptitude remove sudo Reading Package Lists... Building Dependency Tree... Reading extended state information... Initializing package states... Reading task descriptions... Done The following packages will be REMOVED: sudo 0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded. Need to get 0B of archives. After unpacking 369kB will be freed. Writing extended state information... Done (Reading database ... 25809 files and directories currently installed.) Removing sudo ... Reading Package Lists... Done Building Dependency Tree Reading extended state information Initializing package states... Done Reading task descriptions... Done # ls /etc/sudoers /etc/sudoers
Notice that the configuration file has been left behind, but the software and its documentation is gone. To really get rid of all files related to a package, use the
aptitude purge command:
# aptitude purge sudo ... The following packages will be REMOVED: sudo 0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded. Need to get 0B of archives. After unpacking 0B will be used. Do you want to continue? [Y/n/?] Y Writing extended state information... Done (Reading database ... 25788 files and directories currently installed.) Removing sudo ... Purging configuration files for sudo ... ... # ls /etc/sudoers ls: /etc/sudoers: No such file or directory
Understanding the sources.list file is the key to Debian happiness.
As part of the Debian installation process, you will have archive sources set up. View them by reading the file /etc/apt/sources.list. Unless you're running without a network connection, the sources will include the main and the security update archives. The typical contents of sources.list for a new installation include:
deb cdrom:[Debian GNU/Linux stable _Sarge_ - i386 Binary-1]/ unstable contrib main deb http://http.us.debian.org/debian stable main deb-src http://http.us.debian.org/debian stable main deb http://security.debian.org/ stable/updates main contrib
The official repository of Debian software is known as the archive. The
deb lines in the sources.list file instruct APT as to where to find the archive, and which distribution and sections of the archive to access. In this example, the
cdrom source refers to the CD used to start the installation, and the
http sources refer to the network-accessible Debian archive. The
deb-src lines tell APT where to find source code for the software.
Use the netselect-apt package to automatically configure your system to use the fastest possible Debian mirrors.
Debian maintains three concurrent distributions: stable, the official stable release, and testing and unstable, used for development purposes. Within the distributions are three sections of the archive. The vast majority of the software is in main, which contains software deemed free by the Debian Free Software Guidelines and depends only on other software in main. The nonfree section includes software not deemed free by the Debian Free Software Guidelines, and contrib includes free software but has dependencies on other software in contrib or nonfree.
There's another section called non-US, containing software that is problematic to distribute in the United States, usually for patent reasons. You can find a list of non-US Debian packages online. Since the relaxation of U.S. laws on cryptography export, the non-US section has become less important to the typical Debian user.
aptitude update command causes APT to reread the sources from sources.list and update the system's list of available packages. Run this command at least once a week in order to get updates from the security archive. The other stable sources will not vary, apart from when stable update releases occur. Stable update releases do not make major changes to the system. Instead, they fix serious bugs and include any essential updates. See the "What about" section for an explanation of how to keep your system up to date against security and stable update releases.
Interrogate the system's index of packages with
aptitude show command displays a package description:
$ aptitude show sudo Package: sudo State: not installed Version: 1.6.7p5-2 Priority: optional Section: admin Maintainer: Bdale Garbee <firstname.lastname@example.org> Uncompressed Size: 369k Depends: libc6 (>= 2.3.2.ds1-4), libpam0g (>= 0.76), libpam-modules Description: Provide limited super user privileges to specific users Sudo is a program designed to allow a sysadmin to give limited root privileges to users and log root activity. The basic philosophy is to give as few privileges as possible but still allow people to get their work done.
The maintainer listed in the package information is the Debian developer who looks after the package. Don't report problems straight to him, though! Read more about how to report Debian bugs here.
Depends line of the descriptions shows which other packages need installing for sudo to run. If they're not already installed when you install a package,
aptitude will install the dependencies too. If a package is installed as a dependency rather than being installed explicitly,
aptitude will remove it when other packages don't depend on it anymore. As well as dependencies, packages can also recommend and suggest other packages. If a package recommends another, it means that although the package will work without the recommendation installed, in all ordinary uses it should be there. Suggestions are more an indication of usefulness than dependency. By default,
aptitude automatically installs all the dependencies and recommendations along with the package itself.
Some software packages simply can't coexist with others. There aren't many of these in Debian, but there are a few. In this case the package information also includes the conflicts relationship. When you ask for a package to be installed that conflicts with one you already have on your system,
aptitude will remove the conflicting package. The most common usage of conflicts in Debian is when a package reorganization or renaming occurs, so that the new package must replace its predecessors when upgraded.
You may not always know which package you need to install in order to get the software you want. Debian package names don't always exactly match the original software. The
aptitude search command searches through the index and displays a list of suitable matches. Use the
~d option to search the description:
$ aptitude search sudo p dpsyco-sudo - Automate administration of sudo privileges p gnome-sudo - dumb package to provide smooth upgrade to p sudo - Provide limited super user privileges to s $ aptitude search ~d"super user" p calife - Provides super user privileges to specific p sudo - Provide limited super user privileges to s
Many more searching options are available, documented in the
aptitudeuser manual, details of which are at the end of this article.
Are there more user-friendly ways to manage packages? Perhaps most people understandably think that a modern operating system should have a more interactive way of installing software, although some people will always be command-line addicts. The visual mode of
aptitude provides a keyboard- and menu-driven interface to your system's packages, as shown in Figure 1. Invoke the visual mode just by running
aptitude on its own. You don't need to bother to become root; when it needs superuser privileges,
aptitude's interface will ask you for the root password.
Figure 1. aptitude in visual mode
All the features available from the command line are accessible through the menus. The display of packages and their state conveys a lot of information at once. For instance, the
i shows a package is installed, and the
A denotes that
aptitude automatically installed it as a dependency. This display is fully customizable through the Options menu.
If you're operating in a graphical environment, you may prefer to use
synaptic, available from the package of the same name. Start it by selecting Synaptic Package Manager from the GNOME System Tools menu, or running
sudo /usr/sbin/synaptic. Figure 2 shows the result of a search for
Figure 2. The Synaptic package manager--click for full-size image
If you plan to use
aptitude from the command line, the best reference is the
aptitude(8) manual page. For the menu-driven interface, a user guide is present in HTML in the /usr/share/doc/aptitude/html directory. Read it with the
w3m text-mode browser or a graphical browser of your choice.
As well as searching for packages on your own system, there's a web interface to all the Debian distributions and their contents, where you can search packages by practically every criteria imaginable.
For further information on the arrangement of the Debian archive, and the significance of the section names, consult Chapter 2 of the Debian Policy Manual. To better understand the meaning of dependencies, recommendations, and other package relationships, consult Chapter 7.
Although I prefer to use
aptitude as the main interface to package management, the
apt-get tool has existed for longer. Its manual page and associated documentation is also a good place to look to learn about package management in Debian.
Edd Dumbill is co-chair of the O'Reilly Open Source Convention. He is also chair of the XTech web technology conference. Edd conceived and developed Expectnation, a hosted service for organizing and producing conferences. Edd has also been Managing Editor for XML.com, a Debian developer, and GNOME contributor. He writes a blog called Behind the Times.
Return to the Linux DevCenter.
Copyright © 2009 O'Reilly Media, Inc.