UNIX / Linux keyboard.

Package Management on Linux, BSD, and Solaris

A Package Management Phrase Book for RPM/yum/urpmi, apt-get/dpkg, pkg, pkg*, and pkg_*

System administrators must manage software packages. With a mix of Unix-family operating systems, you must use the commands specific to each platform. On Red-Hat-derived systems, these include rpm, yum, and urpmi. On Debian derivatives such as the many Ubuntu variants, these include apt-get and dpkg. On FreeBSD, one command pkg does it all. On OpenBSD, it's a family of commands starting pkg_*, and on Solaris, similarly named pkg*. Here are explanations through examples of how to manage software packages and answer questions about installed or missing software using these commands across all those operating systems.

The Linux Standard Base and distribution information give you a general overview of the system: The files /etc/*release contain pieces of this information.

# lsb_release -a
# more /etc/*release /etc/lsb-release.d/*

Red Hat invented the RPM (Red Hat Package Manager) package management system. It includes databases in /var/lib/rpm/* and the rpm command-line interface. RPM is used on many Linux distributions. Pretty much all Linux distributions use rpm for package management, except for Debian and its derivatives like Ubuntu, plus Slackware, where you use tar and take very notes.

The two commands yum (found on most RPM-based distributions) and urpmi (found on Mageia and other Mandrake derivatives) are high-level wrappers around rpm, giving it the same automation and ease of use found with Debian's apt-get. If you don't use either yum or urpmi then for installation or upgrade you must have the desired package and all its dependencies on the local system. You can figure out the dependencies on your own. But that can take long enough that by the time you finally install the now huge list of packages you have forgotten what you were trying to do in the first place.

Debian and Ubuntu use the dpkg and apt-get commands to manage packages.

I have also included the OpenBSD package management tools pkg_add, pkg_info, and pkg_delete here. The pkg_add command does it own dependency management.

FreeBSD used to use the same pkg_* commands as OpenBSD, but it now has one command pkg to do everything. There is a pkg2ng command to convert the old package database to the new format.

Finally, I have included the Solaris package management tools pkgadd, pkginfo, pkgchk, and pkgrm.

Configuring Repositories

All of these except Solaris can use repositories, usually called "repos". You can define one (or possibly many) network or local repos. Then you can install or upgrade a package by simply giving its name, the tool searches the repo on the local file system or the remote server to find what you want.

The repos also contain metadata, a representation of the graph of package interdependencies. That's a large dataset, it's often in the form of a compressed XML file. But the details don't matter to you, the whole point is that if you point your tool to a well-maintained repo, it can figure things out for you!

YUM Repositories

Configure repos to add multimedia support on RHEL/CentOS

The file /etc/yum.conf configures the overall behavior of the yum command. Repo definitions go in separate files within the directory /etc/yum.repos.d, with any name ending ".repo". It might look like the following example, in which the first repo definition is enabled. The second repo has been defined but it will not be used:

name=Nux.Ro RPMs for general desktop use
baseurl=http://li.nux.ro/download/nux/dextop/el7/$basearch/ http://mirror.li.nux

name=Nux.Ro RPMs for general desktop use - testing

Debian / Ubuntu / Mint / etc Linux Repositories

These distributions tend to be graphically oriented, so you could use a graphical tool as described at Ubuntu. But you can also use the command line and add lines to any file with the suffix .list within the directory /etc/apt/sources.list.d/. It also uses any uncommented lines in the file /etc/apt/sources.list. The idea is that the sources.list file is from your distribution, and all you should do in there is change whether something is commented out or not. Do customizations in files you create within the sources.list.d directory. For example, for the "saucy" release of Ubuntu the file sources.list could contain the following to include the packages, the updates, and the source code:

deb http://us.archive.ubuntu.com/ubuntu/ saucy universe
deb-src http://us.archive.ubuntu.com/ubuntu/ saucy universe
deb http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe 

FreeBSD Repositories

The behavior of the pkg command is configured by the file /usr/local/etc/pkg.conf. A repo is defined in /etc/pkg/FreeBSD.conf, and that definition is over-ridden by anything in /usr/local/etc/pkg/repos/FreeBSD.conf. The default /etc/pkg/FreeBSD.conf looks like this:

# $FreeBSD: head/etc/pkg/FreeBSD.conf 263937 2014-03-30 15:24:17Z bdrewery $
# To disable this repository, instead of modifying or removing this file,
# create a /usr/local/etc/pkg/repos/FreeBSD.conf file:
#   mkdir -p /usr/local/etc/pkg/repos
#   echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf

FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes

OpenBSD Repositories

OpenBSD is a little different, it uses an environment variable PKG_PATH instead of a file. That variable names one or more local directories or URLs. If the requested file is not in the current working directory, PKG_PATH is searched. Here is how to update all installed packages from the master FTP site with two commands. First, in csh/tcsh:

# setenv PKG_PATH ftp://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -p`
# pkg_add -u

And in sh/bash:

# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -p`
# pkg_add -u

Below is a "phrase book" listing package management actions and how to do them in all of the command sets.

Commands for Package Management

For the Linux rpm commands and the Solaris pkgadd commands, the package file must be on the local system.

For the Linux yum, urpmi, and apt-get commands, the package file is downloaded from a network repository.

For the OpenBSD pkg_add commands, the package file can be on the local system or downloaded from a network repository, as described above.

Install package foo

Linux RPM rpm -Uvh foo-1.2.3.i386.rpm
yum install foo
urpmi foo
Linux apt-get/dpkg apt-get install foo
FreeBSD pkg pkg install foo
OpenBSD pkg_add pkg_add foo-1.2.3.tgz
Or, using "stems", just name the package and the tool will look for that name plus -version.tgz
pkg_add foo
Solaris pkgadd pkgadd -d ./foo-1.2.3.gz
Or, if the package file is stored in the standard directory of /var/spool/pkg/
pkgadd foo-1.2.3.gz

Upgrade package foo when an earlier version is already installed

Linux RPM rpm -Uvh foo-1.2.3.i386.rpm
yum upgrade foo
urpmi foo
Linux apt-get/dpkg apt-get update
apt-get upgrade foo
FreeBSD pkg pkg upgrade foo
OpenBSD pkg_add pkg_add -u foo
Solaris This is done with patchadd as there should be a patch. If there is not a patch, remove the current version with pkgrm and then add the new one with pkgadd.

Check to see which packages have upgrades available

Linux RPM yum check-update
urpmi.update -a
Linux apt-get/dpkg apt-get update
FreeBSD pkg pkg update
pkg upgrade -n
OpenBSD pkg_add pkg_add -u -n
Solaris See if you have mail from Oracle...

Update all packages with available upgrades

Linux RPM yum upgrade
urpmi --auto-select
Linux apt-get/dpkg apt-get upgrade
FreeBSD pkg pkg upgrade
OpenBSD pkg_add pkg_add -u
In theory, that should be enough. But some package updates might fail when you are updating from one release to the next. So, you can tell it to waive the failsafes and run scripts that might fail:
pkg_add -u -D update
Solaris Again, this is not really automated. You can put a list of patches into a file and then do something like this:
patchadd -M /var/sadm/spool patchlist

Remove the installed package foo

Linux RPM rpm --erase foo
Linux apt-get/dpkg apt-get remove foo

That leaves its old configuration files in place. To also remove them:
apt-get purge foo

To automatically remove all packages no longer needed because they were automatically installed as dependencies of packages which themselves already have been removed:
apt-get autoremove
FreeBSD pkg pkg delete foo
OpenBSD pkg_add pkg_delete foo
Solaris pkgrm pkgrm foo

Remove "orphaned" or "leaf" packages, those installed to satisfy dependencies but which are no longer needed

Linux RPM yum autoremove
urpme --auto-orphan
Linux apt-get/dpkg apt-get autoremove
FreeBSD pkg pkg autoremove
OpenBSD pkg_info pkg_delete -a

List all packages currently installed on the system

Linux RPM rpm -qa
Linux apt-get/dpkg dpkg -l
FreeBSD pkg pkg info
OpenBSD pkg_info pkg_info
Solaris pkginfo pkginfo

List all available packages in the repositories

Linux RPM yum list
urpmq --list | sort -u
Linux apt-get/dpkg apt-get update
apt-cache dumpavail

Or, to search for packages related to the topic OpenSSL:
apt-get update
apt-cache search openssl
FreeBSD pkg pkg search '.*'
This works by regular expression, not file name wildcards, so use '.*' to match everything. You could also search for every package containing some string within its name:
pkg search '.*samba.*'
or starting with some string:
pkg search '^samba.*'

Display the information about the installed package foo

Linux RPM rpm -qi foo
Linux apt-get/dpkg dpkg -s foo
FreeBSD pkg pkg info foo
OpenBSD pkg_info pkg_info foo
Solaris pkginfo pkginfo -l foo

List the files belonging to the installed package foo

Linux RPM rpm -ql foo
Linux apt-get/dpkg dpkg --listfiles foo
FreeBSD pkg pkg info -l foo
pkg --list-files foo
OpenBSD pkg_info pkg_info -L foo
Solaris grep foo /var/sadm/install/contents
The second field of each line specifies the file type:
f file
s symbolic link in form link=file
d directory

Which package owns the file /etc/foo.conf?

Linux RPM rpm -qf /etc/foo.conf
Linux apt-get/dpkg dpkg -S /etc/foo.conf
FreeBSD pkg pkg which /etc/foo.conf
OpenBSD pkg_info pkg_info -E /etc/foo.conf
Solaris pkgchk -l -p /etc/foo.conf
Or, more simply:
grep /etc/foo.conf /var/sadm/install/contents
The second field of each line specifies the file type:
f file
s symbolic link in form link=file
d directory

Which package could I add to get the file /etc/foo.conf?

Linux RPM yum provides /etc/foo.conf
urpmf /etc/foo.conf
Linux apt-get/dpkg dpkg-query -S /etc/foo.conf
apt-file search /etc/foo.conf

Dependencies: Which other packages does the foo package require?

Linux RPM rpm -qR foo
Linux apt-get/dpkg apt-cache depends foo
FreeBSD pkg pkg info -d foo
pkg info --dependencies foo
OpenBSD pkg_info There doesn't seem to be an easy way of doing this, but it can be done:

$ for P in $( pkg_info -a | awk '{print $1}' )
> do
>    echo $P $( pkg_info -R $P | grep foo ) | awk '/foo/ {print $1}'
> done
Solaris For at least a partial list:
patchadd -p | grep foo

Reverse dependencies: Which other packages require the foo package?

Linux RPM rpm --whatrequires foo
Linux apt-get/dpkg apt-cache rdepends foo
FreeBSD pkg pkg info -r foo
pkg info --required-by foo
OpenBSD pkg_info pkg_info -R foo

Non-dependencies: Which packages are not required by any other packages and thus could be easily removed?

FreeBSD pkg pkg autoremove -n
OpenBSD pkg_info pkg_info -t

I installed a large number of packages, many of which displayed messages about needed manual steps. How can I see all the installation messages?

OpenBSD pkg_info pkg_info -aM | less

Verify all installed packages, reporting files that have been removed, changed, or had ownership or permission changed

Linux RPM rpm -a --verify
Linux apt-get/dpkg debsums
FreeBSD pkg pkg check -s -a
OpenBSD pkg_check pkg_check
Solaris pkginfo | awk '{print $2}' | xargs pkgchk

For even more tricks, see this Ubuntu page.