UNIX / Linux keyboard.

Package Management on Linux, BSD, and Solaris

A Package Management Phrase Book for RPM/yum/urpmi, apt/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 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.

Quick Overview

Here is an three-in-one table for Linux, both rpm/yum and apt/dpkg, plus FreeBSD. Those three cover almost all of what I use these days. Following this are more detailed explanations of these commands, plus the commands for Linux rpm/urpmi, OpenBSD and Solaris.

Task Linux rpm/yum Linux dpkg/apt FreeBSD
Check and update repos yum check-update apt update pkg update
Install foo rpm -Uvh foo.rpm
yum install foo
apt install foo
dpkg -i foo.deb
pkg install foo
Upgrade foo rpm -Uvh foo.rpm
yum upgrade foo
apt upgrade foo pkg upgrade foo
Upgrade all yum upgrade apt full-upgrade pkg upgrade
Remove foo rpm --erase foo apt remove foo
apt purge foo
pkg delete foo
Remove "orphans" yum autoremove apt autoremove pkg autoremove
List installed packages rpm -qa apt list --installed
dpkg -l
pkg info
List available in repos yum list apt list --all-versions
apt-cache dumpavail
pkg search .
Show info about foo rpm -qi foo apt show foo
dpkg -s foo
pkg info foo
List files in foo rpm -ql foo dpkg --listfiles foo pkg info -l foo
pkg --list-files foo
Which package owns /etc/foo? rpm -qf /etc/foo dpkg -S /etc/foo pkg which /etc/foo
Which package could provide /etc/foo? yum provides /etc/foo apt search /etc/foo
What does foo require? rpm -qR foo apt-cache depends foo pkg info -d foo
What requires foo? rpm --whatrequires foo apt-cache rdepends foo pkg info -r foo
Verify all packages rpm -a --verify debsums pkg check -s -a

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. 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 commands to manage packages. (apt has replaced apt-get as of Ubuntu 16.04.) Higher-level tools include aptitude, synaptic, and wajig.

I have also included the OpenBSD package management tools pkg_add, pkg_info, and pkg_delete here. The pkg_add command does its 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 Apt 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 "groovy" 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/ groovy universe
deb-src http://us.archive.ubuntu.com/ubuntu/ groovy universe
deb http://us.archive.ubuntu.com/ubuntu/ groovy-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ groovy-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:

FreeBSD: {
  mirror_type: "srv",
  signature_type: "fingerprints",
  enabled: yes

Maintaining FreeBSD

Freebsd uses the freebsd-update tool to maintain the base system. You then use pkg to maintain the packages you have added.

To download updates to the kernel and userspace tools:

# freebsd-update fetch 

To install the downloaded updates:

# freebsd-update install 

That updates the base operating system environment, the kernel and userspace. Then you use pkg to maintain the added packages. So, the full sequence would be:

[... Download base userland and kernel updates ...]
# freebsd-update fetch
[... Install base userland and kernel updates ...]
# freebsd-update install
[... Update the package database ...]
# pkg update
[... Download and install package updates ...]
# pkg upgrade 

To upgrade FreeBSD to a newer release, see the release installation instructions. Generally speaking, it goes like this:

[... Get the current installation fully updated ...]
# freebsd-update fetch
# freebsd-update install
# pkg update
# pkg upgrade

[... Update to the new release, manually merging
     changes in configuration files when prompted.
     Expect the first command to take about an hour
     to run.  ...]
# freebsd-update upgrade -r XX.Y-RELEASE
# freebsd-update install

[... Reboot to the new kernel ...]
# shutdown -r now

[... Install the new userland components ...]
# freebsd-update install

[... If prompted to do so, rebuild third-party
     applications and run "freebsd-update install"
     again ...]

[... Reboot to the new environment ...]
# shutdown -r now 

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 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.i686.rpm
yum install foo
urpmi foo
Linux apt/dpkg apt 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.i686.rpm
yum upgrade foo
urpmi foo
Linux apt/dpkg apt update
apt 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/dpkg apt update
apt list --upgradable
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/dpkg apt upgrade
New packages will be installed, but existing packages will never be removed.

apt full-upgrade
apt-get dist-upgrade
Install new packages, removing existing packages as needed to satisfy dependencies.
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, if necessary,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 patch1 patch2 ...

Remove the installed package foo

Linux RPM rpm --erase foo
Linux apt/dpkg apt remove foo
The above leaves locally customized configuration files in place. To also remove them:
apt purge foo
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/dpkg apt 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/dpkg apt list --installed
dpkg -l
Two commands with different output format.
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/dpkg apt update
apt list --all-versions

Or, for another method:
apt update
apt-cache dumpavail

Or, to search for packages related to the topic OpenSSL:
apt 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/dpkg apt show foo
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/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/dpkg dpkg -S /etc/foo.conf
apt-file search /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/dpkg apt search /etc/foo.conf

Dependencies: Which other packages does the foo package require?

Linux RPM rpm -qR foo
Linux apt/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/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/dpkg debsums
FreeBSD pkg pkg check -s -a
OpenBSD pkg_check pkg_check
Solaris pkginfo | awk '{print $2}' | xargs pkgchk

Act on a package file, not on a package that has been installed

Linux RPM Add the -p option to an rpm command.
Linux apt/dpkg Use dpkg-deb instead of dpkg.

Work with package groups, not individual packges

Linux RPM yum group list
List the available groups.
yum group summary
Show how many groups are installed out of how many available.
yum group info foo
Show a very short description of the foo group, and a list of packages it contains.
yum group install foo
Install all packages in the foo group.
yum group remove foo
Remove all packages in the foo group.
Linux apt/dpkg tasksel
Run an interactive menu showing the available groups (called "tasks"), and which are installed. You can select groups for installation and removal.
tasksel --list-tasks
Display the current list.

For even more tricks, see this Ubuntu page.