Package Find for OpenBSD using pkg_find


OpenBSD has a decent set of tools to install packages from the web site or ftp site of your choice. The problem is, none of them are as quick and easy to use as "pkg_find" by Michael Erdely.

Pkg_find allows you to setup the repository or your choice and then search that repository by package name. The script then compiles a list of all the packages it found and you pick the number of the one you want to install. This makes setting up a new box or adding packages to an existing box incredibly fast.

How it works

The following is an example of what pkg_find shows if we ask to install postfix on an OpenBSD v4.1 machine. Note, we did _not_ have to specify the version number or any other information. And, unlike "pkg_add -i", pkg_find will also list files that are close to your query term. This way you can still get a package listing even if you do not quite know how to spell the package name. All packages with postfix in the name are displayed and we can choose the package we want by the number listed to the left.

root@machine: pkg_find postfix
     1  mailman-2.1.9-postfix
     2  postfix-2.3.7-ldap
     3  postfix-2.3.7-mysql
     4  postfix-2.3.7-sasl2
     5  postfix-2.3.7
     6  postfix-2.4.20070125-ldap
     7  postfix-2.4.20070125-mysql
     8  postfix-2.4.20070125-sasl2
     9  postfix-2.4.20070125
Pick which package to add: 

When you choose the package number pkg_find uses the package tools already installed by OpenBSD like pkg_add. The package chosen and its dependencies will painlessly be installed from the remote repository. This makes compatibility between platforms a non-issue.

Below is the single pkg_find script already compiled and it works on i386 and amd64 systems without issue. You can download it here at or you can get the source if you prefer to build it.

You can download the pkg_find script here by doing a "save as" or just clicking on the link and choosing download. Before using the script take a look the "how to" below or download it and look at the options. pkg_find or source

Starting the install

Step 1: The first step is to download pkg_find from above or build it from source. You may find it easier to use if the script is located in /usr/local/sbin/ in root's path. This way you can use just the name and leave out the full path. Also, change the permissions on pkg_find to 555 just to be safe. Our example install looks like so:

root@machine: ls -al /usr/local/sbin/pkg_find
-r-xr-wr-w  1 root  wheel  8058 Jan 01 12:00 /usr/local/sbin/pkg_find

Step 2: Now setup the environmental variable PKG_PATH to the repository you want to fetch files from. This can be either a ftp site (ftp://) or web site (http://). As a side note, pkg_find can _not_ use an environmental variable which lists more than one repository. For the example, we are going to using the repository at, using the shell ksh or bash and put _one_ of the two lines below into root's .profile file. Once the file has been edited execute "source .profile" for the changes to take affect. You can check that PKG_PATH is active by executing "env" and looking for it.

Specify the os version and architecture manually
    export PKG_PATH=

or use the follow to remain os version portable
    export PKG_PATH=`uname -r`/packages/`arch -s`/

Step 3: You can now update the pkg_find package listing from the remote server. Execute "pkg_find -u" and it will take a few seconds to collect the current names. The script will make a directory called ".pkg_find/" in root's home directory and a file with the database listing in it.

You are now ready to install packages using pkg_find.


Can pkg_find use a PKG_PATH listing multiple repositories?

No, it can not. If you want to use multiple ftp/ http servers in your PKG_PATH then you must stick to using the default pkg_add tool instead of pkg_find.

How do I setup multiple repositories in PKG_PATH (pkg_add use only)?

The following line shows an example of both repositories and being set to PKG_PATH. If the package is not found on the first server pkg_add will check the second server. Put this line in .profile for ksh/bash shells.

NOTE: it is important to remember that the repositories both end with a slash "/" and are separated by a colon ":". This format is required to make PKG_PATH valid.

export PKG_PATH=`uname -r`/packages/`arch -s`/:`uname -r`/packages/`arch -s`/

What arguments will pkg_find accept?

user@machine: pkg_find --help
Usage: pkg_find [-h] [-u] [-i|-n] [-p|-q] [-v] [-d] [-t] search_string
        -i|--install    Install package
        -n|--no-install Do not install package
        -p|--prompt     Prompt to install when just one match
        -q|--quiet      Do not prompt to install when just one match
        -u|--update     Update package list (if -u is specified and no
                        search_string, list will update and script will
        -v|--verbose    Be verbose
        -d|--debug      Debug
        -t|--test       Test mode. Print command that would be run
        -V|--version    Print version and exit
        -h|--help       Print this screen and exit

What does "Can't install `X` because of conflicts" mean?

When installing a package the process was interrupted. Now the package is partially installed. The error might look something like this:
$ pkg_add -v freebsd_lib-4.11p0.tgz
parsing freebsd_lib-4.11p0.tgz
Can't install freebsd_lib-4.11p0 because of conflicts (partial-freebsd_lib-4.11p0)
/usr/sbin/pkg_add: freebsd_lib-4.11p0:Fatal error

To fix this you need to do a pkg_delete on the partial package install. For example, to clear the message for a the error above we would use the following command before trying to install the package again:

pkg_delete partial-freebsd_lib-4.11p0

Questions, comments, or suggestions? Contact