# LPI Linux Certification/Use Debian Package Management
## Detailed Objective

(LPIC-1 Version 5.0
Weight: 3
Description:
Candidates should be able to perform package management using the Debian package tools.
Key knowledge areas:
* Install, upgrade and uninstall Debian binary packages.
* Find packages containing specific files or libraries which may or may not be installed.
* Obtain package information like version, content, dependencies, package integrity and installation status (whether or not the package is installed).
* Awareness of apt.
The following is a partial list of the used files, terms and utilities:
* /etc/apt/sources.list
* dpkg
* dpkg-reconfigure
* apt-get
* apt-cache

## Package Structure

In order to understand how to use Debian's package management system, it would be useful to first have an understanding of how a Debian package is named. For example, the package ncftp_3.1.3-1_i386.deb has 5 major parts:
* ncftp - the name of the program/application/library
* 3.1.3 - the version of the program/application/library assigned by the original (upstream) author(s)
* 1 - the revision number of the package assigned by the person(s) who packaged the program for a Debian system
* i386 - the architecture the packaged program is designed to run on
* .deb - signifies this is a Debian package
Note that there is special significance to the use of underscores(_) and hyphens(-); an underscore shall separate the name of the program and its version, a hyphen shall separate a version number and the revision number, and an underscore shall separate the revision number and the architecture.

## dpkg

dpkg is the "grandaddy" or "back-end" of the Debian Package Management System. Features present in the more advanced tools are not available to dpkg but it is nevertheless a useful tool.
Some notes:
* dpkg keeps its record of available packages in /var/lib/dpkg/available.
Some of the more common functions used by administrators by dpkg are:
Adding, Removing, and Configuring Packages
* dpkg {-i|--install} <package-name> will install the specified package
* dpkg {-r|--remove} <package-name> will remove the specified package (but leave the configuration files intact)
* dpkg {-P|--purge} <package-name> will remove the specified package and the corresponding configuration files
* dpkg --root /target -i <package> will install a package into a unbootable system by specifying the system root.
* dpkg --unpack <package-name> will unpack (but do not configure) a Debian archive into the file system of the hard disk
* dpkg --configure <package-name> will configure a package that already has been unpacked
Querying Package Information
* dpkg --info <package-name> will print out the control file (and other information) for a specified package
* dpkg {-l|--list} this will give you a list of installed packages.
* dpkg {-a|--pending} is given instead of a package name, then all packages unpacked, but marked to be removed or purged in file /var/lib/dpkg/status, are removed or purged, respectively.
* dpkg -s (--status) <package-name> will give you a description of installed package
Updating Package Information
* dpkg --update-avail <package-name> will replace old information with with new information from package.
* dpkg --merge-avail <package-name> will combine old information with new information from package.

## dpkg-reconfigure

dpkg-reconfigure reconfigures packages after they have already been installed.
* dpkg-reconfigure <package-name> to reconfigure the initial installation settings
* dpkg-reconfigure --priority=medium package [...] will set the minimum priority of question that will be displayed
* dpkg-reconfigure --all will reconfigure all packages
* dpkg-reconfigure locales will generate any extra locales
* dpkg-reconfigure --p=low xserver-xfree86 will reconfigure X server

## Dselect

The utility that allows you on Debian to easily add/remove packages is dselect.
* Choose the access method to use.
* Update the list of available packages, if possible.
* Request which packages you want on your system.
* Install and upgrade wanted packages.
* Configure any packages that are unconfigured.
* Remove unwanted software.
There is on dselect an interactive menu that will allow you to install/remove packages. Care must be taken with this utility. You can damage your system.
Dselect menu example:

## apt-get

If you know the name of a package you want to install, use apt-get. You must configure the sources.list file. This same file is used when you choose the apt access method of dselect. The location is /etc/apt.
* apt-get install <package-name> will search its database for the most recent version of this package and will retrieve and install it from the corresponding archive as specified in sources.list. In the event that this package depends on another APT will check the dependencies and install the needed packages.
** apt-get install <package-name>=<version> will install a package at the version specified
** apt-get install <package-name> -o DPkg::options::="--force-overwrite" installs a package ignoring "error processing ..., which is also in package ..." errors.
* apt-get remove <package-name> will remove the specified package but keep its configuration files.
* apt-get --purge remove <package-name> will remove the specified package and its configuration files.
* apt-get -u install <package-name> will upgrade and install a specific package.
* apt-get -u upgrade will upgrade packages within the same distribution packages except those which have been kept back because of broken dependencies or new dependencies.
* apt-get -u dist-upgrade will upgrade an entire Debian system at once.

## apt-file

* apt-file search <file-name> will search for a package which includes the specified file.
* apt-file list <package-name> will list the contents of a package matching the pattern. This action is very close to the dpkg -S command except the package does not need to be installed or fetched.

## Apt-cache

To find the name of a package that you want to install use apt-cache. apt-cache main options are :
* add - Add a package file to the source cache
* showpkg - Show some general information for a single package
* stats - Show some basic statistics
* search - Search the package list for a regex pattern
* show - Show a readable record for the package
* depends – Show raw dependency information for a package

## Resources

APT HOWTO http://www.debian.org/doc/manuals/apt-howto/index.en.html dselect Documentation for Beginners http://www.debian.org/doc/manuals/dselect-beginner/

## Exercises

* Exercises results
* Install a system with Debian.
* Get familiar with dselect and remove the tcpdump utility.
* Install back with apt-get the package that contains the tcpdump utility.
* Try kpackage to install ethereal