Linux Package Management

Author: Sam Kleinman1External Link
Published: July 16, 2009
Revised: July 2, 2010

In many of these tutorials we speak of "package managers" and "package management tools." If you're new to the Linux world and don't quite understand what all the fuss is about, or if you're familiar with one package management tool but need to learn how to use another, this guide will provide a comparative introduction to major package management tools.

These instructions work with the Linode platform. If you don't have a Linode yet, sign up for a Linux VPS and get started today.

Package Management Concepts Link

Contemporary distributions of Linux-based operating systems install software in pre-compiled "packages" which contain (for most systems) binaries of software, configuration files, and in most systems, information about dependencies. Furthermore, package management tools keep track of updates and upgrades so that we don't have to hunt down information about bug and security fixes.

Without package management, users must ensure that all of the required dependencies for a piece of software are installed and up to date, compile the software from the source code (which takes time, and introduces compiler-based variances from system to system), and manage configuration for each piece of software. Additionally, without package management, application files are located in the (hopefully) standard locations for the system to which the developer(s) are accustomed, regardless of what system you're using. In short, this becomes an utter mess.

Package management systems attempt to solve these problems, and are the tools through which developers attempt to increase the overall quality and coherence of a Linux-based operating system. Pursuant to these goals the features that (most) package management applications provide are:

  • Package downloading: operating system projects provide repositories of packages which allow users to download their packages from a single, cryptographically-trusted provider. When you download from a package manager, the software can be authenticated and will remain in the repository even if the original "upstream" source becomes unreliable.
  • Dependency resolution: packages contain meta-data which provides information about what other packages are required by the package in question. This allows applications and their dependencies to be installed with one command, and for programs to rely on common shared libraries, reducing bulk and allowing the operating system to manage updates to the packages.
  • A standard binary package format: packages are prepared in a uniform way across the system in order to make installation easier and more coherent. While some distributions share formats--eg. Debian and Ubuntu both use .deb; CentOS, Fedora, Mandrivia and OpenSuSE use .rpm--there can be substantial compatibility issues between similarly formatted packages for different operating systems.
  • Common installation and configuration locations: System developers often have conventions for how applications are configured and the layout of files in the /etc/ and /etc/init.d/ directories; by using packages, systems are able to enforce this conformity.
  • Additional system-related configuration and functionality: Occasionally, operating system developers will develop patches and helper scripts for their software which get distributed in the packages. These modifications range from minimal to more substantive and can have a great impact on usability and user experience.
  • Quality control. Operating system developers use the packaging process to test and ensure that the software is stable and free of bugs that might encroach upon product quality, and that the software doesn't cause the system to become unstable. The subjective judgments and community standards that guide packaging and package management to a great extent guide the "feel" and "stability" of a given system.

In general we recommend, when installing new software, that you install the versions of software available in your distribution's repository and packaged for your operating system. If packages for the application or software that you need to install isn't available, we recommend that you find packages for your operating system or package the software rather than installing it manually.

The remainder of this guide will cover how to use specific package management systems, including how to compile and package software yourself.

Debian and Ubuntu Package Management Link

The Debian package management system, based on a tool called dpkg with the very popular apt system is an incredibly powerful, popular, and useful method of package management. In addition to Debian 5 (known as "Lenny") a number of other prominent distributions of GNU/Linux are derived from the Debian system, most notably the Ubuntu family of distributions.

As a result these instructions are applicable for Debian and Ubuntu systems. While Debian and derived systems are not necessarily binary-compatible, .debs packaged for Debian are often compatible with Ubuntu (though this is not a supported workflow). Let's begin by reviewing some basic commands.

Advanced Packaging Tool, (apt) Link

Chances are good that you're already familiar with apt-get, a command which uses the "advanced package tool" to interact with the operating system's underlying package system. The most relevant and useful commands are, (to be run as root):

  • apt-get install [package-name] - This command installs the package(s) specified, along with any dependencies.
  • apt-get remove [package-name] - This command removes the package(s) specified, but does not remove dependencies.
  • apt-get autoremove - This command removes any "orphaned" dependencies which remain installed but are not used by any applications.
  • apt-get clean - Removes downloaded package files (.deb) for software that are already installed.
  • apt-get purge [optional] - Combines the functions of remove and clean for a specific package. Also removes configuration files for the given package.
  • apt-get update - Reads the /etc/apt/sources.list file and updates the system's database of packages available for installation. Run this after changing sources.list.
  • apt-get upgrade - Upgrades all packages if there are updates available. Run this after running apt-get update.

While apt-get likely provides the most often used functionality of the package management, apt provides additional information that you may find useful in the apt-cache command.

  • apt-cache search [package-name] - If you know the name of a piece of software but apt-get install fails or points to the wrong software, use search to look for other possible names, if you need to find out the name of a package that you know is in the system.
  • apt-cache show [package-name] - The search interface only provides package names. If you need to learn more about a package, including dependency information, version numbers and a basic description, run this.
  • apt-cache depends [package name(s)] - Lists the packages that the specified packages depends upon in a tree. These are the packages that will be installed with the apt-get install command.
  • apt-cache rdepends [package name(s)] - Generates and outputs a list of packages that that depend upon the specified package. This list can often be rather long.
  • apt-cache pkgnames - Generates a list of the currently installed packages on your system. This list is often rather long, so it is best to pipe its output through a command like less.

In general, combining most of these commands with apt-cache show can provide you with a lot of useful information about your system, the software that you might want to install, and the software that you have already installed. If interacting with this information via the command line is difficult, both Debian and Ubuntu provide websites which present this information in an easier-to-see framework. If you're overwhelmed by apt-cache check out:

aptitude Link

aptitude is another front-end interface for apt. It provides a graphical command line (via ncurses) interface to apt, which you might find useful for an easier approach to daily administrative tasks.

In addition to the graphical interface, aptitude provides a combined command line interface for most apt functionality. The salient commands are:

  • aptitude update, aptitude install, aptitude remove, aptitude clean, aptitude purge - Same as their apt-get counterparts.
  • aptitude search, aptitude show, - Same as their apt-cache counterparts.
  • aptitude download - Downloads a .deb file for a given package into the current directory.

Aptitude also includes advanced functionality for "safe" upgrading (an upgrade that doesn't remove existing packages), as well as preventing the system from upgrading specific packages ("holding"). If this kind of functionality would be useful for you we encourage you to use the aptitude interface.

Introducing /etc/apt/sources.list Link

The file /etc/apt/sources.list controls which repositories apt constructs its database from. This file contains lines in the following format:

Here are some examples:

The first line specifies the Columbia University mirror for the the "Lenny" distribution (Debian 5.0, Stable Release 14 February 2009), as well as the main and contributed components. The next line specifies the emacs.orebokech.com repository for Lenny, which provides regularly updated packages for emacs-snapshot (versions of emacs23, built from the current CVS tree), and its main component.

In general one does not want to add new entries to sources.list without a lot of scrutiny and diligence, as updating the package cache with additional repositories and running upgrades can sometimes result in the installation of broken packages, unmet dependencies, and system instability. In Debian systems, downgrading is often difficult.

For Debian systems, the repository names can either refer to the distribution code name (version specific; eg. lenny for current-stable, squeeze for testing, sid for unstable, etch for old-stable) or to a specific branch (eg, oldstable, stable, testing, unstable). For more information about Debian versions and choosing a Debian version or branch, read the Debian releases and branches page5External Link.

The component section of the line divides the repository based on how much support the developers of the operating system are able to offer for the contained packages (eg. main vs. contrib), or if the software is considered "free-software" or simply freely-distributable (eg. non-free).

The layout of sources.list is a bit different in Ubuntu systems. The lines are in the same format but the names of the distributions and components are different:

  • Ubuntu versions have a different naming scheme. Version 8.10 is named hardy in sources.list, 9.04 is jaunty, and 9.10 is karmic. These names follow an alphabetical pattern.
  • Ubuntu components are: "main" and "restricted" for supported free and non-free packages; "universe" and "multiverse" for unsupported free and non-free software.

Using dpkg Link

apt-get and apt-cache are merely front-ends that provide a more usable interface, and connections to repositories for the underlying package management tools called dpkg and debconf. These tools are quite powerful, and fully documenting their functionality is beyond the scope of this document. However, a basic understanding of how to use these tools is useful. The most useful commands are:

  • dpkg -i [package-file-name].deb - Installs a .deb file.
  • dpkg --list [search-pattern] - Lists packages currently installed on the system.
  • dpkg --configure - Runs a configuration interface to set a package up.
  • dpkg-reconfigure - Runs a configuration interface on an already installed package.

For more information about building your own packages, refer to the Debian New Maintainers Guide6External Link

Fedora and CentOS Package Management Link

Fedora and CentOS are closely related distributions, being upstream and downstream (respectively) from Red Hat Enterprise Linux. Their main differences stem from how packages are chosen for inclusion in their repositories. From a package management perspective the tools are very similar.

Both systems use the yum program as a front end to interact with system repositories and install dependencies, and also include a lower level tool called rpm which allows you to interact with individual rpm packages.

Note: Many operating systems aside from RedHat and Fedora use rpm packages. These include OpenSuSE, AIX, and Mandriva; while it may be possible to install an RPM packaged for one operating system on another, this is not supported or recommended, and the results of this action can vary greatly.

Yellow Dog Updater, Modified (yum) Link

The yum tool was initially developed for the Yellow Dog Linux system as a replacement for the then-default Yellow Dog Updater (yup). RedHat found the yum tool to be a valuable addition to their systems. Today yum is the default package and repository management tool for a number of operating systems.

From the command line, you can use the following subset of commands to interact with yum:

  • yum install [package-name(s)] - This command installs the specified package(s) along with any required dependencies.
  • yum erase [package-name(s)] - This command removes the specified package(s) from your system.
  • yum search [search-pattern] - The search command searches the list of package names and descriptions for packages that match the search pattern and provides a list of package names, with architectures and a brief description of the package contents. Note that regular expression searches are not permitted.
  • yum deplist [package-name] - deplist provides a listing of all of the libraries and modules that the named package depends on, along with the names of the packages (including versions) that provide those dependencies.
  • yum check-update - This command refreshes the local cache of the yum database so that dependency information and the latest packages are always up to date.
  • yum info [package-name] - The results of the info command provides the name, description of the package, as well as a link to the upstream home page for the software, release versions and the installed size of the software.
  • yum reinstall [package-name(s)] - This command erases and then downloads a new copy of the package file and re-installs the software on your system.
  • yum localinstall [local-rpm-file] - This command checks the dependencies of an .rpm file and then installs it.
  • yum update [optional-package-name] - Downloads and installs all updates including bug fixes, security releases, and upgrades, as provided by the distributors of your operating system. Note that you can specify package names with the update command.
  • yum upgrade - Upgrades all packages installed in your system to the latest release.

RPM package manager (rpm) Link

In many ways yum is simply a front end to a lower-level package management tool called rpm, similar to apt-get's relationship with dpkg. The chances are good that you will not need to interact with rpm very much, but there are a few commands that you may find useful.

The following commands should be run as root. The flags are expanded here in the pursuit of clarity, but the more conventional terse syntax is also included.

  • rpm --install --verbose --hash [local-rpm-file-name].rpm - More conventionally, rpm -ivh [filename].rpm installs an rpm from the file. rpm is also capable of installing RPM files from http and ftp sources as well as local files.
  • rpm --erase [packag-name] - Often used as rpm -e, this command removes the given package. Usually will not complete if [package-name] matches more than one package, but will remove more than one match if used with the --allmatches flag.
  • rpm --query --all - Conventionally rpm -qa, this command lists the name of all packages currently installed.
  • rpm --query [package-name] - Often simply rpm -q, allows you to confirm or deny if a given package is installed in your system.
  • rpm --query --info [package-name] - Or, rpm -qi, displays the information about an installed package.
  • rpm --query --list [package-name] - Often, rpm -ql, will generate a list of files installed by a given package. This is complemented by:
  • rpm --query --file or rpm -q qf [file-name] checks to see what installed package "owns" a given file.

(_Note:_ rpm does no dependency resolution. You must install dependencies manually when using rpm.) For more information about rpm please consult these external sources:

  • iDevelopment Info - RPM Commands <http://www.idevelopment.info/data/Unix/Linux/LINUX_RPMCommands.shtml>
  • Quick Guide to RPM <http://www.tfug.org/helpdesk/linux/rpm.html>

Introducing /etc/yum.conf Link

The file located at /etc/yum.conf provides system-wide configuration options for yum, as well as information about repositories. Repository information may also be located in files ending in .repo under /etc/yum.repos.d

The options in the [main] stanza are pretty self-explanatory and shouldn't need modification, though you set alternate logging and cache locations for the database with the following lines in /etc/yum.conf:

To define a new stanza for a new repository use the following template, replacing the capitalized strings with actual values:

The following example is the default configuration for the "Base" repository in CentOS 5.2:

Package Management in ArchLinux with pacman Link

ArchLinux uses binary packages in a .tar.gz format, and also provides a "ports" build system that facilitates building packages.

The Arch tool, pacman is sophisticated, complete, modern and provides rich and helpful output. ArchLinux runs on a "rolling release" schedule, which means packages are added to the main repository when they (and their dependencies) are deemed ready for production. This means that there aren't release versions of Arch, as all systems once upgraded are of equivalent version.

Therefore it is incumbent upon administrators of ArchLinux to consider the output of pacman carefully before agreeing to upgrade or update any packages.

Introducing pacman: An Overview Link

While the pacman tool is very powerful, it is also very simple. We encourage you to become more familiar with the tool, but there are three core commands for basic package management: The list below include the verbose and terse forms of the command:

  • pacman --query [package] or more tersely pacman -Q - Use this command to search the package database for a package name and version number.
  • pacman --sync [package(s)] or more tersely pacman -S - This is the base command for installing new packages, downloading new content for the database and upgrading the system, depending on the options and the named package or packages.
  • pacman --remove [package(s)] or more tersely pacman -R- Removes the named package or packages.

Note that the terse flags are all uppercase and case-sensitive. These terse flags are often combined with additional flags for additional functionality. Here are some examples and a brief description of the functionality they provide:

  • pacman -Qi [package-name] - Displays information about a given package, including dependency information, the date of the package, a link to the upstream source and other useful information about a package.
  • pacman -Qo [file-name] - Outputs the version number and name of the package which "owns" a given file.
  • pacman -Qs [package-name] - Searches among the installed packages for a given package-name.
  • pacman -Qu - Lists out-of-date installed packages that are in need of an update.
  • pacman -Q [package-name] - Searches the package database for a given package-name.
  • pacman -Sy - The -Sy flag triggers a database refresh, and synchronizes the local database with the remote database.
  • pacman -Su - The update flag triggers a full system update and downloads new packages to upgrade the system. The update and refresh command can (and should, particularly after installing a new Arch installation,) be run together, as in: pacman -Syu
  • pacman -Sc - The clean tag removes uninstalled packages from the cache and attempts to clean up old copies of the repository database.
  • pacman -S --ignore [package-name] - The ignore flag instructs pacman to ignore upgrades to a given package or list of packages.
  • pacman -S [package-name] - The sync command, when run with a package name, installs the package and its dependencies.
  • pacman -Rs The remove-recursive option removes a package and its dependencies, as long as the dependencies are not needed and were not explicitly installed by the user. This command is the inverse of pacman -S.
  • pacman -Ru Removes packages that are unneeded by any other packages.

Configuration Options Link

pacman's configuration is defined in the /etc/pacman.conf file, while the addresses of the repository mirrors are contained in /etc/pacman.d/mirrorlist. The mirror list was created and prioritized during the installation process and you probably will not need to alter this.

The options provided in the stock /etc/pacman.conf are reasonably self explanatory and are beyond the scope of this document. (You may access the manual page for this configuration file with the command man pacman.conf).

While it is unlikely that you would need to modify the default pacman.conf for most installations, know that inside of pacman.conf you can change default installation and logging directories and specify packages to be held back from upgrades.

Additionally, if you need to add an additional third party repository to pacman, you can do that by adding a repository stanza like this:

Note, the Server = and Include = lines are both optional, and the order of presentation of servers and includes indicates their priority. By default, the testing repository is disabled, which is probably wise if you're planning to use the system for production work; however if you need bleeding-edge packages, uncomment those lines.

Using the Arch Build System (ABS) Link

The Arch Build System provides a method for users to compile and install software not included in the Arch repository within the pacman framework. This brief guide outlines the steps to building a package using the abs.

All commands explained here should be run as root. Begin by installing the abs framework and the base-devel packages using the following command:

Now, edit /etc/abs.conf so that the REPOS line indicates all of the proper repositories. Note, repositories prefixed with a bang (eg. !) are disabled. The line might look like:

To create a local ABS tree in /var/abs, run the the abs command as root. You may now browse /var/abs which contains a representation of the package collection with folders representing each repository, category, and piece of software.

Arch recommends that you create a build directory at another location, perhaps ~/abs/, where actual building will occur.

Begin the build process by copying the files from the ABS tree into your build directory, like so (not as root):

Now, change to the package's directory:

You have the option of modifying the PKGBUILD file. There's a build shell function where you can add additional patches to the files if you have any modifications to the software or the build process if you need to. That shell function generally looks like:

Now you're ready to build the package. Use the following command as a normal, non-root user:

makepkg creates a package that contains dependency information. As root, issue the following command:

Make sure to type the full package name exactly as it appears in the file system. Arch will now install the package and any required dependencies.

Because the ABS system downloads source and versions of the PKGBUILD file as it creates the package--sometimes checking out a copy of the source code from the version control system, we don't recommend deleting or removing files from the build directory hierarchy.

More Information About Pacman and ABS Link

If you're interested in learning more about Arch and its package management tools, please consult these external sources for the documentation provided by the Arch community.

Gentoo Linux Package Management Link

The Gentoo Linux operating system is a unique and flexible distribution. Gentoo provides the entire operating system in source format. These source packages, in concert with "ebuild" scripts, provide a sophisticated package management system that borrows and builds on many concepts from the BSD world's "ports" system.

Compiling the entire system from source is purported to offer some slight performance benefit, though this benefit may be hard to discern in a virtualized environment. Furthermore, the process of compiling software from source takes a significant amount of time. Nevertheless, many users enjoy the portage framework and the Gentoo operating system for specialized deployments.

Like Arch Linux, the Gentoo project produces new versions of Gentoo Linux on a "rolling release" cycle. In these distributions new versions of individual packages are released when the packages are deemed ready for production.

This section addresses common package management tasks and functions using the "emerge" front end for the portage system. We encourage you to install the "gentoolkit" to provide additional package management tools, such as equery. You can install this package with the following command:

Emerge/Portage Commands Link

  • "emerge --sync" updates the local copy of the portage tree, so that your local system can download and install the latest version of the software.
  • "emerge --update --deep world" checks and updates all packages on the system to the latest version. This should be run regularly to avoid falling behind on a critical update.
  • "emerge --search [keyword]" or "emerge -s [keyword]" searches the names of all of the packages for the given keyword. This command takes a regular expression as the keyword argument.
  • "emerge --searchdoc [keyword]" or "emerge -S [keyword]" searches the full description for a given keyword. This command takes a regular expression as the keyword argument.
  • "emerge [package-name]" installs the specified package or packages.
  • "emerge -u [package-name]" updates the specified package to the latest version.
  • "emerge -uD [package-name]" updates the specified package and all of its dependencies.
  • "emerge --unmerge [package-name]" or "emerge -C [package-name]" removes the specified package or packages. This does not perform dependency checking, so it's possible to remove a package which is required by another package. Furthermore, this command does not remove dependencies which were installed with the specified application but are not depended upon by any other package (e.g. orphaned packages.)
  • "emerge --depclean --pretend" tests the removal of orphaned packages and generates a list of packages that would be removed so that the administrator can insure that crucial dependencies are not removed in error.
  • "emerge --depclean" removes packages that are orphaned. This means removal of all packages that weren't explicitly installed and are not not depended upon by any specific package. We recommend that you run it with the --pretend option before running this command on a production system.
  • "emerge -evp --deep world" lists all of the packages currently installed on the system.
  • "equery depends [package-name]" lists all of the packages that depends upon the specified package.
  • "equery files [package-name]" lists all of the files "owned" by a package.
  • "equery belongs [file-name]" lists the package which "owns" a particular file.

USE Flags Link

Portage also makes it possible to install additional variants of a package with the "USE flags" options. To discover which USE flags are available for a given package, issue the following command:

The equery command depends on the gentoolkit package. This will provide information about what USE flags are available and which have been installed. To specify additional USE flags, issue a command in the following form:

This will install the specified package with the appropriate options enabled.

License Link

This guide is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License9External Link. Please feel free to redistribute unmodified copies of it as long as attribution is provided, preferably via a link to this page.

Citations

  1. <http://library.linode.commailto:docs@linode.com> Sam Kleinman
  2. <http://www.linode.com/?r=f4ac5ae5f59e43a8b31de8077ceab27bd1e60c80> Linux VPS
  3. <http://packages.debian.org> The Debian Package Directory
  4. <http://packages.ubuntu.com> The Ubuntu Package Directory
  5. <http://www.us.debian.org/releases/> Debian releases and branches page
  6. <http://www.debian.org/doc/maint-guide/> Debian New Maintainers Guide
  7. <http://wiki.archlinux.org/index.php/ABS_-_The_Arch_Build_System> The Arch Build System
  8. <http://wiki.archlinux.org/index.php/Pacman> Pacman
  9. <http://creativecommons.org/licenses/by-nd/3.0/us/> Creative Commons Attribution-No Derivative Works 3.0 United States License