[BACK]Return to faq15.html CVS log [TXT][DIR] Up to [local] / www / faq

File: [local] / www / faq / faq15.html (download) (as text)

Revision 1.185, Mon Nov 15 18:21:59 2021 UTC (2 years, 6 months ago) by tj
Branch: MAIN
CVS Tags: HEAD
Changes since 1.184: +17 -19 lines

simplify "updating packages" section by only explaining how to update all
installed packages, not individual ones. while here, make update/upgrade
usage more consistent. ok tb

<!doctype html>
<html lang=en id=faq>

<!-- If you make edits to any FAQ documents, please start each sentence
     on a new line, and try to keep the general formatting consistent
     with the rest of the pages -->

<title>OpenBSD FAQ: Package Management</title>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../openbsd.css">
<link rel="canonical" href="https://www.openbsd.org/faq/faq15.html">

<!--
Copyright (c) 2005-2009 Steven Mestdagh <steven@openbsd.org>

Permission to use, copy, modify, and distribute this documentation for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.

THE DOCUMENTATION IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS DOCUMENTATION INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS DOCUMENTATION
-->

<h2 id=OpenBSD>
<a href="../index.html">
<i>Open</i><b>BSD</b></a>
FAQ - Package Management
<small>
<a href="index.html">[FAQ Index]</a>
</small>
</h2>
<hr>

<ul>
  <li><a href="#Intro"        >Introduction</a>
  <li><a href="#Mirror"       >Selecting a Mirror</a>
  <li><a href="#PkgFind"      >Finding Packages</a>
  <li><a href="#PkgInstall"   >Installing Packages</a>
  <li><a href="#PkgUpdate"    >Updating Packages</a>
  <li><a href="#PkgRemove"    >Removing Packages</a>
  <li><a href="#PkgDup"       >Duplicating Installed Packages on Another
                               Machine</a>
  <li><a href="#PkgPartial"   >Incomplete Package Installation or Removal</a>
</ul>

<hr>

<h2 id="Intro">Introduction</h2>

There are many applications one might want to use on an OpenBSD system.
To make this software easier to install and manage, it is <i>ported</i>
to OpenBSD and packaged.
The aim of the package system is to keep track of which software gets
installed, so that it may be easily updated or removed.
In minutes, a large number of packages can be fetched and installed, with
everything put in the right place.

<p>
The ports collection does <b>not</b> go through the same thorough security
audit that is performed on the OpenBSD base system.
Although we strive to keep the quality of the packages high, we just do not
have enough resources to ensure the same level of robustness and security.

<p>
The OpenBSD ports team considers packages to be the goal of their porting
work, not the ports themselves.
In general, you are advised to use packages over building an application
from ports.

<p>
Packages can be easily managed with the help of several utilities:

<ul>
  <li><a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a>
  - for installing and updating packages
  <li><a href="https://man.openbsd.org/pkg_check">pkg_check(8)</a>
  - for checking the consistency of installed packages
  <li><a href="https://man.openbsd.org/pkg_delete">pkg_delete(1)</a>
  - for removing installed packages
  <li><a href="https://man.openbsd.org/pkg_info">pkg_info(1)</a>
  - for displaying information about packages
</ul>

In order to run properly, application X may require that other applications
Y and Z be installed.
Application X is said to be dependent on these other applications, which is
why Y and Z are called <i>dependencies</i> of X.
In turn, Y may require other applications P and Q, and Z may require
application R to function properly.
This way, a whole dependency tree is formed.

<p>
Packages look like simple <code>.tgz</code> bundles.
Basically they are just that, but there is one crucial difference:
they contain some extra <i>packing information</i>.
This information is used by
<a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a> for several purposes:

<ul>
  <li>Different checks: has the package already been installed, or does it
      conflict with other installed packages or file names?
  <li>Dependencies which are not yet present on the system are automatically
      fetched and installed before proceeding with the installation of the
      package.
  <li>Information about the package(s) is recorded in a central repository,
      located in <code>/var/db/pkg</code> by default.
      This will, among other things, prevent the dependencies of a package
      from being deleted before the package itself has been deleted.
      This helps ensure that an application cannot be accidentally broken
      by a careless user.
</ul>

<h2 id="Mirror">Selecting a Mirror</h2>

There are two places <a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a>
will look for packages:
the <a href="https://man.openbsd.org/installurl">installurl(5)</a> file
(<code>/etc/installurl</code>) or the <code>PKG_PATH</code> environment
variable.
The former is the preferred method and is configured by default on new
installations.

<p>
If the use of multiple mirrors is needed, <code>PKG_PATH</code> allows this
via a colon-separated list:

<pre class="cmdbox">
# <b>export PKG_PATH=scp://user@company-build-server/usr/ports/packages/%a/all:https://trusted-public-server/%m:installpath</b>
</pre>

While the default should work well for most people, a list of alternate
locations can be found on the <a href="../ftp.html">mirrors page</a>.

<h2 id="PkgFind">Finding Packages</h2>

A large collection of pre-compiled packages is available for the most common
architectures.

<p>
To search for any given package name, use the <code>-Q</code> flag of
<a href="https://man.openbsd.org/pkg_info">pkg_info(1)</a>.

<pre class="cmdbox">
$ <b>pkg_info -Q unzip</b>
lunzip-1.8
unzip-6.0p9
unzip-6.0p9-iconv
</pre>

Another way to find what you're looking for is with the <code>pkglocate</code>
command, available from the <code>pkglocatedb</code> package.

<pre class="cmdbox">
$ <b>pkglocate mutool</b>
mupdf-1.11p1-js:textproc/mupdf,js:/usr/local/bin/mutool
mupdf-1.11p1-js:textproc/mupdf,js:/usr/local/man/man1/mutool.1
mupdf-1.11p1:textproc/mupdf:/usr/local/bin/mutool
mupdf-1.11p1:textproc/mupdf:/usr/local/man/man1/mutool.1
</pre>

If you're looking for a specific filename, it can be used to find which
package(s) contain that file.

<p>
You will notice that certain packages are available in a few different
varieties.
These are called <b>flavors</b>.
The <a href="ports/ports.html#PortsFlavors">ports FAQ</a> explains flavors
in detail, but it basically means they're configured with different sets
of options.
For example, a package might have optional database support, support for
systems without X11, etc.
Some packages are also divided into <b>subpackages</b> that may be
installed separately.

<p>
Not all possible packages are necessarily available on the mirror servers.
Some applications simply don't work on all architectures.
Some applications cannot be distributed via mirrors for licensing reasons.

<h2 id="PkgInstall">Installing Packages</h2>

The <a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a> utility is used
to install packages.
If multiple flavors of a package exist, you will be prompted to choose which
one you want to install.

<pre class="cmdbox">
# <b>pkg_add rsync</b>
Ambiguous: choose package for rsync
a       0: &lt;None&gt;
        1: rsync-3.1.2p0
        2: rsync-3.1.2p0-iconv
Your choice:
</pre>

Here you would select <b>1</b> if you want the standard package or <b>2</b>
if you need iconv support.
You can also choose the flavor directly on the command line by using
<code>pkg_add rsync--</code> (for the default) or
<code>pkg_add rsync--iconv</code> (for the iconv flavor).

<p>
It is possible to specify multiple package names on one line, which then
all get installed at once, along with their dependencies.
You may also specify the absolute location of a package, be it a local
file or remote URL.
Supported URL prefixes are http, https, ftp and scp.

<p>
For some packages, important additional information will be given about
the configuration or use of the application.

<pre class="cmdbox">
# <b>pkg_add jove</b>
jove-4.16.0.73p0: ok
--- +jove-4.16.0.73p0 -------------------
See /usr/local/share/jove/README about changes to /etc/rc or
/etc/rc.local so that the system recovers jove files
on reboot after a system crash
</pre>

Additionally, some packages provide configuration and other information
in a file located in <code>/usr/local/share/doc/pkg-readmes</code>.

<p>
For your safety, if you are installing a package which you had installed
earlier and removed, configuration files which have been modified will
not be overwritten.
The same is true for when you update a package.

<p>
Sometimes you may encounter an error like the one in the following example:

<pre class="cmdbox">
# <b>pkg_add xv</b>
xv-3.10ap4:jpeg-6bp3: ok
xv-3.10ap4:png-1.2.14p0: ok
xv-3.10ap4:tiff-3.8.2p0: ok
Can't install xv-3.10ap15 because of libraries
|library X11.16.1 not found
| not found anywhere
Direct dependencies for xv-3.10ap15 resolve to png-1.6.31 jasper-1.900.1p5 tiff-4.0.8p1 jpeg-1.5.1p0v0
Full dependency tree is png-1.6.31 tiff-4.0.8p1 jasper-1.900.1p5 jpeg-1.5.1p0v0
</pre>

The packing information bundled in the package includes information
about shared libraries that the package expects to be installed.
If one of the required libraries can't be found, the package is not
installed because it would not function anyway.

<p>
There are several things to check:

<ul>
<li>Your system may be incomplete: you did not install one of the
<a href="faq4.html#FilesNeeded">file sets</a> that contains the required
library.
<li>Your system (or packages) may be outdated: you have an older version
of the required library.
Make sure that both the base system and any installed packages are up to date.
<li>If you're running -current, base and package snapshots may be slightly
out of sync.
Wait for the mirrors to catch up and try again.
</ul>

<h2 id="PkgUpdate">Updating Packages</h2>

Installed packages can be updated with
<a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a> like so:

<pre class="cmdbox">
# <b>pkg_add -u</b>
</pre>

This will attempt to update all installed packages, including their
dependencies.

<h2 id="PkgRemove">Removing Packages</h2>

To remove a package, simply use
<a href="https://man.openbsd.org/pkg_delete">pkg_delete(1)</a>:

<pre class="cmdbox">
# <b>pkg_delete screen</b>
</pre>

Again, modified configuration files will not be removed.

<p>
Dependencies that are no longer needed can afterwards be removed with the
<code>-a</code> flag:

<pre class="cmdbox">
# <b>pkg_delete -a</b>
</pre>

<h2 id="PkgDup">Duplicating Installed Packages on Another Machine</h2>

Installing a new OpenBSD system with the same set of packages as an older
machine is a fairly common use case.
The <code>-mz</code> flags of
<a href="https://man.openbsd.org/pkg_info">pkg_info(1)</a> will yield
appropriate results to make this task easier.

<ul>
  <li>The <code>-m</code> flag only selects packages that were manually
      installed.
      Dependencies are not recorded, as they're pulled in automatically.
  <li>The <code>-z</code> flag excludes version information from the output.
      Only the flavor and branch are displayed, ensuring that future package
      installations will select the appropriate version.
</ul>

For instance:

<pre class="cmdbox">
$ <b>pkg_info -mz | tee list</b>
abcde--
mpv--
python--%3.6
vim--no_x11
</pre>

Copy the "list" file over to the other machine and run:

<pre class="cmdbox">
# <b>pkg_add -l list</b>
</pre>

Every package specification has a flavor (<code>--</code> being the default)
appended to its name, and packages that co-exist in several versions also
have branch information.
In this case, subsequent
<a href="https://man.openbsd.org/pkg_add">pkg_add(1)</a> commands will select
the current python package of the <code>3.6</code> version branch.

<h2 id="PkgPartial">Incomplete Package Installation or Removal</h2>

In some odd cases, you may find a package was not added completely,
due to conflicts with other files.
The incomplete installation is usually marked with "partial-" prepended to
the package name.
This can, for instance, happen when you coincidentally press CTRL+C during
installation.
The installation can be later completed, and the "partial-*" package will
disappear, or it can be removed with
<a href="https://man.openbsd.org/pkg_delete">pkg_delete(8)</a>.
<p>
More dire system failures, such as file system issues, may
lead to <code>/var/db/pkg</code> becoming corrupted or inconsistent.
<p>
The <a href="https://man.openbsd.org/pkg_check">pkg_check(8)</a> utility can
help clean things up.