UNIX / Linux keyboard.

Package Management and Service Control on Linux, BSD, and Solaris

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

System administrators must manage software packages. With a mix of Unix-family operating systems, you have to use the commands specific to those platforms. 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. With OpenBSD, it's a family of commands starting pkg_*, and with 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. Put simply (and therefore a little inaccurately), pretty much all Linux distributions use rpm for package management, except for Debian and its derivatives like Ubuntu, plus Slackware, where tar and very careful note-taking remain supreme.

The two commands yum (found on most RPM-based distributions) and urpmi (found on Mageia) 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, and getting the dependencies straighted out can take long enough that you finally install the now huge list of packages only to realize you forgot 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.

With pkg_add you can do both installation and upgrading. The package to be added can be specified as a path to a local file or as a URL. If the files are not in the current working directory, the environment variable PKG_PATH is used to search for them. And yes, PKG_PATH could be set to the URL of an FTP or HTTP server directory containing OpenBSD packages. Here is how to update all installed packages from the master FTP site with two commands:

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

Most recently, I added the Solaris package management tools pkgadd, pkginfo, pkgchk, and pkgrm.

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
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
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
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
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
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
OpenBSD pkg_info pkg_delete -a

List all packages currently installed on the system

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

List all available packages

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

Display the information about the installed package foo

Linux RPM rpm -qi foo
Linux apt-get/dpkg dpkg -s 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
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
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
OpenBSD pkg_info There doesn't seem to be an easy way of doing this. A simple shell script run in a directory where all package files have been downloaded could accomplish it.
Solaris There doesn't seem to be an easy way of doing this.

Dependencies: Which other packages does the foo package require?

Linux RPM rpm -qR foo
Linux apt-get/dpkg apt-cache depends 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
OpenBSD pkg_info pkg_info -R foo

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

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
OpenBSD pkg_check pkg_check
Solaris pkginfo | awk '{print $2}' | xargs pkgchk

For even more tricks, see this Ubuntu page.