<!-- retain these comments for translator revision tracking -->
<!-- Original version: $Revision: 1.29 $ -->
<chapt id="pkgtools">The Debian package management tools

<sect id="pkgprogs">What programs does Debian provide for managing its
  packages?

<p>There are multiple tools that are used to manage Debian packages,
from graphic or text-based interfaces to the low level tools used to
install packages. All the available tools rely on the lower level
tools to properly work and are presented here in decreasing complexity
level.

<p>It is important to understand that the higher level package
management tools such as <prgn/aptitude/ or <prgn/dselect/ rely on
<prgn/apt/ which, itself, relies on <prgn/dpkg/ to manage the packages
in the system.

<p>See <url id="http://www.debian.org/doc/manuals/debian-reference/ch02.en.html" name="Chapter 2. Debian package management"> of the 
<url id="http://www.debian.org/doc/manuals/debian-reference/" 
name="Debian reference">
for more information about the Debian package management utilities.
This document is available in various languages and formats, see <url
id="http://www.debian.org/doc/user-manuals#quick-reference" name="the Debian
Reference entry on the DDP Users' Manuals overview">.

<!-- TODO: Describe tools to automatically build from sources Debian
packages including 'apt-build' or 'pbuilder' (in pkg_basics.sgml) -->

<sect1 id="dpkg">dpkg

<p>This is the main package management program. <prgn/dpkg/ can be
invoked with many options.  Some common uses are:
<list>
  <item>Find out all the options:  <tt>dpkg --help</tt>.
  <item>Print out the control file (and other information) for a specified
    package: <tt>dpkg --info foo_VVV-RRR.deb</tt>
  <item>Install a package (including unpacking and configuring) onto the
    file system of the hard disk: <tt>dpkg --install foo_VVV-RRR.deb</tt>.
  <item>Unpack (but do not configure) a Debian archive into the file system
    of the hard disk: <tt>dpkg --unpack foo_VVV-RRR.deb</tt>.  Note that this
    operation does <em>not</em> necessarily leave the package in a usable
    state; some files may need further customization to run properly.
    This command removes any already-installed version of the program and
    runs the preinst (see <ref id="maintscripts">) script associated with
    the package.
  <item>Configure a package that already has been unpacked:
    <tt>dpkg --configure foo</tt>.  Among other things, this action runs the
    postinst (see <ref id="maintscripts">) script associated with the package.
    It also updates the files listed in the <tt>conffiles</tt> for this
    package. Notice that the 'configure' operation takes as its argument a
    package name (e.g., foo), <em/not/ the name of a Debian archive file
    (e.g., foo_VVV-RRR.deb).
  <item>Extract a single file named "blurf" (or a group of files
    named "blurf*" from a Debian archive:
    <tt>dpkg --fsys-tarfile foo_VVV-RRR.deb | tar -xf - blurf*</tt>
  <item>Remove a package (but not its configuration files):
    <tt>dpkg --remove foo</tt>.
  <item>Remove a package (including its configuration files):
    <tt>dpkg --purge foo</tt>.
  <item>List the installation status of packages containing the string
    (or regular expression) "foo*": <tt>dpkg --list 'foo*'</tt>.
</list>

<sect1 id="apt-get">APT

<p>APT is the <em>Advanced Package Tool</em> and provides the
<prgn/apt-get/ program.  <prgn/apt-get/ provides a simple way to
retrieve and install packages from multiple sources using the command
line.  Unlike <prgn/dpkg/, <prgn/apt-get/ does not understand .deb
files, it works with the packages proper name and can only install
.deb archives from a source specified in
<file>/etc/apt/sources.list</file>. <prgn/apt-get/ will call
<prgn/dpkg/ directly after downloading the .deb
archives<footnote>Notice that there are ports that make this tool
available with other package management systems, like Red Hat package
manager, also known as <prgn/rpm/</footnote> from the configured
sources.

<p>Some common ways to use <prgn/apt-get/ are:

<list>
       <item>To update the list of package known by your system, you can run:
               <example>apt-get update</example>
       (you should execute this regularly to update your package lists)

       <item>To upgrade all the packages on your system (without installing
             extra packages or removing packages), run:
               <example>apt-get upgrade</example>

       <item>To install the <var/foo/ package and all its dependencies, run:
               <example>apt-get install foo</example>

       <item>To remove the foo package from your system, run:
               <example>apt-get remove foo</example>

       <item>To remove the foo package and its configuration files from your
             system, run:
               <example>apt-get --purge remove foo</example>

       <item>To upgrade all the packages on your system, and, if needed for a
             package upgrade, installing extra packages or removing packages, run:
               <example>apt-get dist-upgrade</example>
             (The command <tt>upgrade</tt> keeps a package at its installed
             obsolete version if upgrading would need an extra package to be
             installed, for a new dependency to be satisfied. The
             <tt>dist-upgrade</tt> command is less conservative.)

</list>

<p>Note that you must be logged in as root to perform any commands that
modify the system packages.

<p>Note that <prgn/apt-get/ now installs recommended packages as default and is
the preferred program for package management from console to perform system
installation and major system upgrades for its robustness.

<p>The apt tool suite also includes the <prgn/apt-cache/ tool to query
the package lists. You can use it to find packages providing specific
functionality through simple text or regular expression queries and
through queries of dependencies in the package management system.
Some common ways to use <prgn/apt-cache/ are:

<list>
       <item>To find packages whose description contain <var/word/:
               <example>apt-cache search <var>word</var></example>

       <item>To print the detailed information of a package:
               <example>apt-cache show <var>package</var></example>

       <item>To print the packages a given package depends on:
               <example>apt-cache depends <var>package</var></example>

       <item>To print detailed information of the versions available
               for a package and the packages that reverse-depends on
               it:
               <example>apt-cache showpkg <var>package</var></example>

</list>


<p>For more information, install the <package/apt/ package and read
<manref name="apt-get" section="8">, <manref name="sources.list" section="5">
and install the  <package/apt-doc/ package and read
<file>/usr/share/doc/apt-doc/guide.html/index.html</file>.

<sect1 id="aptitude">aptitude

<p><prgn/aptitude/ is a package manager for &debian; systems that
provides a frontend to the apt package management
infrastructure. <prgn/aptitude/ is a text-based interface using the
curses library, it can be used to perform management tasks in a
fast and easy way.

<p><prgn/aptitude/ provides the functionality of <prgn/dselect/ and
<prgn/apt-get/, as well as many additional features not found in
either program:

<list>
       <item><prgn/aptitude/ offers easy access to all versions of a package.

       <item><prgn/aptitude/ makes it easy to keep track of obsolete
       software by listing it under "Obsolete and Locally Created
       Packages".

       <item><prgn/aptitude/ includes a fairly powerful system for
       searching particular packages and limiting the package
       display. Users familiar with <prgn/mutt/ will pick up quickly,
       as <prgn/mutt/ was the inspiration for the expression syntax.

       <item><prgn/aptitude/ can be used to install the predefined tasks
       available. For more information see <ref id="tasksel">.

       <item><prgn/aptitude/ in full screen mode has <prgn/su/
       functionality embedded and can be run by a normal user. It will
       call <prgn/su/ (and ask for the root password, if any) when you
       really need administrative privileges

</list>

<p>You can use <prgn/aptitude/ through a visual interface (simply run
<tt>aptitude</tt>) or directly from the command line. The command line
syntax used is very similar to the one used in <prgn/apt-get/. For
example, to install the <var>foo</var> package, you can run
<tt>aptitude install <var>foo</var></tt>.

<p>Note that <prgn/aptitude/ is the preferred program for daily package 
management from console.

<p>For more informations, read the manual page <manref
name="aptitude" section="8"> and install the <package/aptitude-doc/
package.

<sect1 id="synaptic">synaptic

<p><prgn/synaptic/ is a graphical package manager.  It enables you to install,
upgrade and remove software packages in a user friendly way.   Next to all
features offered by aptitude, it also has a feature for editing the list of
used repositories, and supports browsing all available documentation related to
a package. See the <url id="http://www.nongnu.org/synaptic/" name="Synaptic
Website"> for more information.


<!-- once these are mature, add a section on them:
      adept-manager (for KDE)
      update-manager (for GNOME)   -->


<sect1 id="tasksel">tasksel

<p>When you want to perform a specific task it might be difficult to
find the appropiate suite of packages that fill your need. 
The Debian developers have defined <tt/tasks/, a task is a collection of
several individual Debian packages all related to a specific activity.
Tasks can be installed through the <prgn/tasksel/ program or through
<prgn/aptitude/.

<p>The Debian installer will typically install automaticaly the task
associated with a standard system and a desktop environment. The specific
desktop environment installed will depend on the CD/DVD media used, most
commonly it will be the GNOME desktop (<tt/gnome-desktop/ task).  Also,
depending on your selections throughout the installation process, tasks might
be automatically installed in your system. For example, if you selected a
language, the task associated with it will be installed automatically too and
if you are running in a laptop system the installer recognises the <tt/laptop/
task will be installed too.

<sect1 id="dpkg-extra">Other package management tools

<sect2 id="dselect">dselect

<p>This program is a menu-driven interface to the Debian package management
system. For woody and earlier releases, this was the main package management interface for
for first-time installations, but currently users are encouraged to use
<prgn/aptitude/ instead. Some users might feel more comfortable using
<prgn/aptitude/ and it is also recommended over <prgn/dselect/ for large-scale
upgrades. For more information on <prgn/aptitude/ please see <ref
id="aptitude">.

<p><prgn/dselect/ can:
<list>
  <item>guide the user as he/she chooses among packages to install or remove,
    ensuring that no packages are installed that conflict with one another,
    and that all packages required to make each package work properly are
    installed;
  <item>warn the user about inconsistencies or incompatibilities in their
    selections;
  <item>determine the order in which the packages must be installed;
  <item>automatically perform the installation or removal; and
  <item>guide the user through whatever configuration process are required
    for each package.
</list>

<p><prgn/dselect/ begins by presenting the user with a menu of 7 items,
each of which is a specific action. The user can select one of the actions
by using the arrow keys to move the highlighter bar, then pressing the
<em>&lt;enter&gt;</em> key to select the highlighted action.

<p>What the user sees next depends on the action he selected.  If he selects
any option but <tt>Access</tt> or <tt>Select</tt>, then <prgn/dselect/
will simply proceed to execute the specified action: e.g., if the user
selected the action <tt>Remove</tt>, then dselect would proceed to remove
all of the files selected for removal when the user last chose the
<tt>Select</tt> action.

<p>Both the <tt>Access</tt> menu item and the <tt>Select</tt> menu item
lead to additional menus.  In both cases, the menus are presented as
split screens; the top screen gives a scrollable list of choices, while
the bottom screen gives a brief explanation ("info") for each choice.

<p>Extensive on-line help is available, use the '?' key to get to a help
screen at any time.

<p>The order in which the actions are presented in the first <prgn/dselect/
menu represents the order in which a user would normally choose
<prgn/dselect/ to install packages.  However, a user can pick any of the
main menu choices as often as needed (including not at all, depending on
what one wants to do).

<list>
  <item>Begin by choosing an <strong/Access Method/.  This is the
    method by which the user plans on accessing Debian packages; e.g., some
    users have Debian packages available on CD-ROM, while others plan to
    fetch them using anonymous FTP. The selected "Access Method" is stored
    after <prgn/dselect/ exits, so if it does not change, then this option
    need not be invoked again.

  <item>Then <strong/Update/ the list of available packages.  To do this,
    <prgn/dselect/ reads the file "Packages.gz" which should be included
    in the top level of the directory where the Debian packages to be
    installed are stored.  (But if it is not there, <prgn/dselect/ will
    offer to make it for you.)

  <item><strong/Select/ specific packages for installation on his system.
    After choosing this menu item, the user is first presented with a full
    screen of help (unless the `--expert' command line option was used).
    Once the user exits the Help screen, he sees the split-screen menu for
    choosing packages to install (or remove).

    <p>The top part of the screen is a relatively narrow window into the
    list of Debian's &all-pkgs; packages; the bottom part of the screen
    contains description of the package or group of packages which are
    highlighted above.

    <p>One can specify which packages should be operated on by highlighting
    a package name or the label for a group of packages. After that, you
    can select packages:
    <taglist>
      <tag>to be installed:
        <item>This is accomplished by pressing the `+' key.
      <tag>to be deleted:
        <item>Packages can be deleted two ways:
        <list>
          <item>removed: this removes most of the files associated with the
          package, but preserves the files listed as configuration files
          (see <ref id="conffile">) and package configuration
          information. This is done by pressing the `-' key.
          <item>purged: this removes <em/every/ file that is part of the
          package. This is done by pressing the `_' key.
        </list>
        Note that it's not possible to remove "All Packages". If you try
        that, your system will instead be reduced to the initial installed
        base packages.
      <tag>to be put "on hold"
        <item>This is done by pressing `=', and it effectively tells
        <prgn/dselect/ not to upgrade a package even if the version
        currently installed on your system is not as recent as the version
        that is available in the Debian repository you are using (this was
        specified when you set the <strong/Access Method/, and acquired when
        you used <strong/Update/).
        <p>Just like you can put a package on hold, you can reverse such
        setting by pressing `:'. That tells <prgn/dselect/ that the
        package(s) may be upgraded if a newer version is available. This is
        the default setting.
    </taglist>

    <p>You can select a different order in which the packages are presented,
    by using the `o' key to cycle between various options for sorting the
    packages. The default order is to present packages by Priority; within
    each priority, packages are presented in order of the directory (a.k.a. 
    section) of the archive in which they are stored. Given this sort order,
    some packages in section A (say) may be presented first, followed by
    some packages in section B, followed by more packages (of lower
    priority) in section A.

    <p>You can also expand meanings of the labels at the top of the screen,
    by using the `v' (verbose) key. This action pushes much of the text that
    formerly fit onto the display off to the right. To see it, press the
    right arrow; to scroll back to the left, press the left arrow.

    <p>If you select a package for installation or removal, e.g.,
    <package/foo.deb/, and that package depends on (or recommends) another
    package, e.g., <package/blurf.deb/, then <prgn/dselect/ will place the
    you in a sub-screen of the main selection screen. There you can choose
    among the related packages, accepting the suggested actions (to install
    or not), or rejecting them. To do the latter, press Shift-D; to return
    to the former, press Shift-U. In any case, you can save your selections
    and return to the main selection screen by pressing Shift-Q.

  <item>Users returning to the main menu can then select the "Install"
    menu item to unpack and configure the selected packages.
    Alternatively, users wishing to remove files can choose the "Remove"
    menu item.  At any point, users can choose "Quit" to exit dselect;
    users' selections are preserved by <prgn/dselect/.
</list>

<sect2 id="dpkg-deb">dpkg-deb

<p>This program manipulates Debian archive(<tt>.deb</tt>) files.
Some common uses are:
<list>
  <item>Find out all the options:  <tt>dpkg-deb --help</tt>.
  <item>Determine what files are contained in a Debian
    archive file:  <tt>dpkg-deb --contents foo_VVV-RRR.deb</tt>)
  <item>Extract the files contained in a named Debian archive into a
    user specified directory:  <tt>dpkg-deb --extract foo_VVV-RRR.deb tmp</tt>
    extracts each of the files in <tt>foo_VVV-RRR.deb</tt> into the
    directory <tt>tmp/</tt>.  This is convenient for examining the contents
    of a package in a localized directory, without installing the package
    into the root file system.
  <item>Extract the control information files from a package:
    <tt>dpkg-deb --control foo_VVV-RRR.deb tmp</tt>.
</list>

<p>Note that any packages that were merely unpacked using <tt/dpkg-deb
--extract/ will be incorrectly installed, you should use <tt/dpkg --install/
instead.

<p>More information is given in the manual page <manref name="dpkg-deb"
section="1">.

<sect2 id="dpkg-split">dpkg-split

<p>This program splits large package into smaller files (e.g., for writing
onto a set of floppy disks), and can also be used to merge a set of split
files back into a single file. It can only be used on a Debian system (i.e.
a system containing the <package/dpkg/ package), since it calls the program
<tt>dpkg-deb</tt> to parse the debian package file into its component records.

<p>For example, to split a big .deb file into N parts,
<list>
  <item>Execute the command <tt>dpkg-split --split foo.deb</tt>.
    This will produce N files each of approximately 460 KBytes long in the
    current directory.
  <item>Copy those N files to floppy disks.
  <item>Copy the contents of the floppy disks onto the hard disk of your
    choice on the other machine.
  <item>Join those part-files together using <tt>dpkg-split --join "foo*"</tt>.
</list>

</sect1>

<sect id="updaterunning">Debian claims to be able to update a running program;
  how is this accomplished?

<p>The kernel (file system) in &debian; systems supports replacing files even
while they're being used.

<p>We also provide a program called <prgn/start-stop-daemon/ which is used
to start daemons at boot time or to stop daemons when the runlevel is
changed (e.g., from multi-user to single-user or to halt). The same program
is used by installation scripts when a new package containing a daemon is
installed, to stop running daemons, and restart them as necessary.

<sect id="whatpackages">How can I tell what packages are already installed
  on a Debian system?

<p>To learn the status of all the packages installed on a Debian system,
execute the command
  <example>dpkg --list</example>

This prints out a one-line summary for each package, giving a 2-letter
status symbol (explained in the header), the package name, the version
which is <em>installed</em>, and a brief description.

<p>To learn the status of packages whose names match the string any
pattern beginning with "foo" by executing the command:
  <example>dpkg --list 'foo*'</example>

<p>To get a more verbose report for a particular package, execute the
command:
  <example>dpkg --status packagename</example>
 
<sect id="listfiles">How to display the files of a package installed?

<p>To list all the files provided by the installed package <tt>foo</tt>
execute the command
	<example>dpkg --listfiles foo</example>
	
<p>Note that the files created by the installation scripts aren't displayed.

<sect id="filesearch">How can I find out what package produced a particular
  file?

<p>To identify the package that produced the file named <tt>foo</tt> execute
either:

<list>
  <item><tt>dpkg --search filename</tt>
    <p>This searches for <tt>filename</tt> in installed packages.
    (This is (currently) equivalent to searching all of the files having the
    file extension of <tt>.list</tt> in the directory
    <tt>/var/lib/dpkg/info/</tt>, and adjusting the output to print the names
    of all the packages containing it, and diversions.)

    <p>A faster alternative to this is the <prgn>dlocate</prgn> tool.
	<example>dlocate -S  filename</example>

  <item><tt>zgrep foo Contents-ARCH.gz</tt>
    <p>This searches for files which contain the substring <tt>foo</tt>
    in their full path names.  The files <tt>Contents-ARCH.gz</tt> (where ARCH
    represents the wanted architecture) reside in the major package directories
    (main, non-free, contrib) at a Debian FTP site (i.e. under 
    <tt>/debian/dists/&releasename;</tt>).  A <tt>Contents</tt> file
    refers only to the packages in the subdirectory tree where it resides.
    Therefore, a user might have to search more than one <tt>Contents</tt>
    files to find the package containing the file <tt>foo</tt>.

    <p>This method has the advantage over <tt>dpkg --search</tt> in that it
    will find files in packages that are not currently installed on your
    system.

  <item><tt>apt-file search <var>foo</var></tt>
    <p>If you install the <package>apt-file</package>, similar to the above, it
    searches files which contain the substring or regular expression
    <tt>foo</tt> in their full path names. The
    advantage over the sample above is that there is no need to retrieve the
    <tt>Contents-ARCH.gz</tt> files as it will do this automatically for
    all the sources defined in <file>/etc/apt/sources.list</file> when
    you run (as root) <tt>apt-file update</tt>.
</list>

<sect id="datapackages">Why doesn't get `foo-data' removed when I 
   uninstall `foo'?  How do I make sure old unused library-packages get
   purged?

<p>Some packages are split in program (`foo') and data
(`foo-data') (or in `foo' and `foo-doc'). This is true for many games,
multimedia applications and
dictionaries in Debian and has been introduced since some users might
want to access the raw data without installing the program or because
the program can be run without the data itself, making it optional.

<p>Similar situations occur when dealing with libraries: generally these get
installed since packages containing applications depend on them.  When the
application-package is purged, the library-package might stay on the system.
Or: when the application-package no longer depends upon e.g. libdb4.2, but upon
libdb4.3, the libdb4.2 package might stay when the application-package is
upgraded.

<p>In these cases, `foo-data' doesn't depend on `foo', so when you
remove the `foo' package it will not get automatically removed by most
package management tools. The same holds true for
the library packages. This is necessary to avoid circular
dependencies. If you use <prgn>aptitude</prgn> (see <ref
id="aptitude">) as your package management tool it will, however,
track automatically installed packages and remove them when no
packages remain that need them in your system.

