# Package Management

Ubuntu features a comprehensive package management system for the installation, upgrade, configuration, and removal of software. In addition to providing access to an organized base of over 24,000 software packages for your Ubuntu computer, the package management facilities also feature dependency resolution capabilities and software update checking.

Several tools are available for interacting with Ubuntu's package management system, from simple command-line utilities which may be easily automated by system administrators, to a simple graphical interface which is easy to use by those new to Ubuntu.

## Introduction

Ubuntu's package management system is derived from the same system used by the Debian GNU/Linux distribution. The package files contain all of the necessary files, meta-data, and instructions to implement a particular functionality or software application on your Ubuntu computer.

Debian package files typically have the extension '.deb', and typically exist in repositories which are collections of packages found on various media, such as CD-ROM discs, or online. Packages are normally of the pre-compiled binary format; thus installation is quick and requires no compiling of software.

Many complex packages use the concept of dependencies. Dependencies are additional packages required by the principal package in order to function properly. For example, the speech synthesis package Festival depends upon the package libasound2, which is a package supplying the ALSA sound library needed for audio playback. In order for Festival to function, it and all of its dependencies must be installed. The software management tools in Ubuntu will do this automatically.

## dpkg

dpkg is a package manager for Debian based systems. It can install, remove, and build packages, but unlike other package management system's it can not automatically download and install packages and their dependencies. This section covers using dpkg to manage locally installed packages:

- To list all packages installed on the system, from a terminal prompt enter:

      dpkg -l

- Depending on the amount of packages on your system, this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed:

      dpkg -l | grep apache2

  Replace apache2 with any package name, part of a package name, or other regular expression.

- To list the files installed by a package, in this case the ufw package, enter:

      dpkg -L ufw

- If you are not sure which package installed a file, dpkg -S may be able to tell you. For example:

      dpkg -S /etc/host.conf
      base-files: /etc/host.conf

  The output shows that the `/etc/host.conf` belongs to the base-files package.

  Many files are automatically generated during the package install process, and even though they are on the filesystem `dpkg -S` may not know which package they belong to.

- You can install a local .deb file by entering:

      sudo dpkg -i zip_2.32-1_i386.deb

  Change `zip_2.32-1_i386.deb` to the actual file name of the local .deb file.

- Uninstalling a package can be accomplished by:

      sudo dpkg -r zip

  Uninstalling packages using dpkg, in most cases, is NOT recommended. It is better to use a package manager that handles dependencies, to ensure that the system is in a consistent state. For example using `dpkg -r` you can remove the zip package, but any packages that depend on it will still be installed and may no longer function correctly.

For more dpkg options see the man page: `man dpkg`.

## Apt-Get

The apt-get command is a powerful command-line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.

Being a simple command-line tool, apt-get has numerous advantages over other package management tools available in Ubuntu for server administrators. Some of these advantages include ease of use over simple terminal connections (SSH) and the ability to be used in system administration scripts, which can in turn be automated by the cron scheduling utility.

Some examples of popular uses for the apt-get utility:

- Install a Package: Installation of packages using the apt-get tool is quite simple. For example, to install the network scanner nmap, type the following:

      sudo apt-get install nmap

- Remove a Package: Removal of a package or packages is also a straightforward and simple process. To remove the nmap package installed in the previous example, type the following:

      sudo apt-get remove nmap

  Multiple Packages: You may specify multiple packages to be installed or removed, separated by spaces.

  Also, adding the --purge options to `apt-get remove` will remove the package configuration files as well. This may or may not be the desired effect so use with caution.

- Update the Package Index: The APT package index is essentially a database of available packages from the repositories defined in the `/etc/apt/sources.list` file. To update the local package index with the latest changes made in repositories, type the following:

      sudo apt-get update

- Upgrade Packages: Over time, updated versions of packages currently installed on your computer may become available from the package repositories (for example security updates). To upgrade your system, first update your package index as outlined above, and then type:

      sudo apt-get upgrade

  For information on upgrading to a new Ubuntu release see .

Actions of the apt-get command, such as installation and removal of packages, are logged in the /var/log/dpkg.log log file.

For further information about the use of APT, read the comprehensive Debian APT User Manual or type:

    apt-get help

## Aptitude

Aptitude is a menu-driven, text-based front-end to the Advanced Packaging Tool (APT) system. Many of the common package management functions, such as installation, removal, and upgrade, are performed in Aptitude with single-key commands, which are typically lowercase letters.

Aptitude is best suited for use in a non-graphical terminal environment to ensure proper functioning of the command keys. You may start Aptitude as a normal user with the following command at a terminal prompt:

    sudo aptitude

When Aptitude starts, you will see a menu bar at the top of the screen and two panes below the menu bar. The top pane contains package categories, such as New Packages and Not Installed Packages. The bottom pane contains information related to the packages and package categories.

Using Aptitude for package management is relatively straightforward, and the user interface makes common tasks simple to perform. The following are examples of common package management functions as performed in Aptitude:

- Install Packages: To install a package, locate the package via the Not Installed Packages package category, for example, by using the keyboard arrow keys and the ENTER key, and highlight the package you wish to install. After highlighting the package you wish to install, press the + key, and the package entry should turn green, indicating it has been marked for installation. Now press g to be presented with a summary of package actions. Press g again, and you will be prompted to become root to complete the installation. Press ENTER which will result in a Password: prompt. Enter your user password to become root. Finally, press g once more and you'll be prompted to download the package. Press ENTER on the Continue prompt, and downloading and installation of the package will commence.

- Remove Packages: To remove a package, locate the package via the Installed Packages package category, for example, by using the keyboard arrow keys and the ENTER key, and highlight the package you wish to remove. After highlighting the package you wish to install, press the - key, and the package entry should turn pink, indicating it has been marked for removal. Now press g to be presented with a summary of package actions. Press g again, and you will be prompted to become root to complete the installation. Press ENTER which will result in a Password: prompt. Enter your user password to become root. Finally, press g once more, and you'll be prompted to download the package. Press ENTER on the Continue prompt, and removal of the package will commence.

- Update Package Index: To update the package index, simply press the u key and you will be prompted to become root to complete the update. Press ENTER which will result in a Password: prompt. Enter your user password to become root. Updating of the package index will commence. Press ENTER on the OK prompt when the download dialog is presented to complete the process.

- Upgrade Packages: To upgrade packages, perform the update of the package index as detailed above, and then press the U key to mark all packages with updates. Now press g whereby you'll be presented with a summary of package actions. Press g again, and you will be prompted to become root to complete the installation. Press ENTER which will result in a Password: prompt. Enter your user password to become root. Finally, press g once more, and you'll be prompted to download the packages. Press ENTER on the Continue prompt, and upgrade of the packages will commence.

The first column of information displayed in the package list in the top pane, when actually viewing packages lists the current state of the package, and uses the following key to describe the state of the package:

- i: Installed package

- c: Package not installed, but package configuration remains on system

- p: Purged from system

- v: Virtual package

- B: Broken package

- u: Unpacked files, but package not yet configured

- C: Half-configured - Configuration failed and requires fix

- H: Half-installed - Removal failed and requires fix

To exit Aptitude, simply press the q key and confirm you wish to exit. Many other functions are available from the Aptitude menu by pressing the F10 key.

## Automatic Updates

The unattended-upgrades package can be used to automatically install updated packages, and can be configured to update all packages or just install security updates. First, install the package by entering the following in a terminal:

    sudo apt-get install unattended-upgrades

To configure unattended-upgrades, edit `/etc/apt/apt.conf.d/50unattended-upgrades` and adjust the following to fit your needs:

    Unattended-Upgrade::Allowed-Origins {
            "Ubuntu &distro-short-codename;-security";
    //      "Ubuntu &distro-short-codename;-updates";
    };

Certain packages can also be blacklisted and therefore will not be automatically updated. To blacklist a package, add it to the list:

    Unattended-Upgrade::Package-Blacklist {
    //      "vim";
    //      "libc6";
    //      "libc6-dev";
    //      "libc6-i686";
    };

The double // serve as comments, so whatever follows "//" will not be evaluated.

To enable automatic updates, edit `/etc/apt/apt.conf.d/10periodic` and set the appropriate apt configuration options:

    APT::Periodic::Update-Package-Lists "1";
    APT::Periodic::Download-Upgradeable-Packages "1";
    APT::Periodic::AutocleanInterval "7";
    APT::Periodic::Unattended-Upgrade "1";

The above configuration updates the package list, downloads, and installs available upgrades every day. The local download archive is cleaned every week.

You can read more about apt Periodic configuration options in the `/etc/cron.daily/apt` script header.

The results of unattended-upgrades will be logged to `/var/log/unattended-upgrades`.

### Notifications

Configuring Unattended-Upgrade::Mail in `/etc/apt/apt.conf.d/50unattended-upgrades` will enable unattended-upgrades to email an administrator detailing any packages that need upgrading or have problems.

Another useful package is apticron. apticron will configure a cron job to email an administrator information about any packages on the system that have updates available, as well as a summary of changes in each package.

To install the apticron package, in a terminal enter:

    sudo apt-get install apticron

Once the package is installed edit `/etc/apticron/apticron.conf`, to set the email address and other options:

    EMAIL="root@example.com"

## Configuration

Configuration of the Advanced Packaging Tool (APT) system repositories is stored in the /etc/apt/sources.list configuration file. An example of this file is referenced here, along with information on adding or removing repository references from the file.

Here is a simple example of a typical `/etc/apt/sources.list` file.

You may edit the file to enable repositories or disable them. For example, to disable the requirement of inserting the Ubuntu CD-ROM whenever package operations occur, simply comment out the appropriate line for the CD-ROM, which appears at the top of the file:

    # no more prompting for CD-ROM please
    # deb cdrom:[&distro-apt-cd-name; - Release i386 (20070419.1)]/ &distro-short-codename; main restricted

### Extra Repositories

In addition to the officially supported package repositories available for Ubuntu, there exist additional community-maintained repositories which add thousands more potential packages for installation. Two of the most popular are the Universe and Multiverse repositories. These repositories are not officially supported by Ubuntu, but because they are maintained by the community they generally provide packages which are safe for use with your Ubuntu computer.

Packages in the Multiverse repository often have licensing issues that prevent them from being distributed with a free operating system, and they may be illegal in your locality.

Be advised that neither the Universe or Multiverse repositories contain officially supported packages. In particular, there may not be security updates for these packages.

Many other package sources are available, sometimes even offering only one package, as in the case of package sources provided by the developer of a single application. You should always be very careful and cautious when using non-standard package sources, however. Research the source and packages carefully before performing any installation, as some package sources and their packages could render your system unstable or non-functional in some respects.

By default, the Universe and Multiverse repositories are enabled but if you would like to disable them edit `/etc/apt/sources.list` and comment the following lines:

    deb http://archive.ubuntu.com/ubuntu &distro-short-codename; universe multiverse
    deb-src http://archive.ubuntu.com/ubuntu &distro-short-codename; universe multiverse

    deb http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename; universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename; universe
    deb http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename;-updates universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename;-updates universe

    deb http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename; multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename; multiverse
    deb http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename;-updates multiverse
    deb-src http://us.archive.ubuntu.com/ubuntu/ &distro-short-codename;-updates multiverse

    deb http://security.ubuntu.com/ubuntu &distro-short-codename;-security universe
    deb-src http://security.ubuntu.com/ubuntu &distro-short-codename;-security universe
    deb http://security.ubuntu.com/ubuntu &distro-short-codename;-security multiverse
    deb-src http://security.ubuntu.com/ubuntu &distro-short-codename;-security multiverse

## References

Most of the material covered in this chapter is available in man pages, many of which are available online.

- The InstallingSoftware Ubuntu wiki page has more information.

- For more dpkg details see the dpkg man page.

- The APT HOWTO and apt-get man page contain useful information regarding apt-get usage.

- See the aptitude man page for more aptitude options.

- The Adding Repositories HOWTO (Ubuntu Wiki) page contains more details on adding repositories.