Openbsd install or add binary software package howto

by on November 7, 2006 · 5 comments· LAST UPDATED November 8, 2006

in

OpenBSD logo

Just like FreeBSD, OpenBSD comes with pkg_add command. It is used to install a binary or upgrade packages from http or ftp mirror over internet. If you have purchased OpenBSD DVD/CD you can install packages from CD itself.

pkg_add command used to update existing packages too.

Task: Add package from ftp or http mirror

Use generic OpenBSD mirror such as follows:
ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/amd64/ or ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/i386/
Please note that version number (4.) and machine architecture (amd64). You can find complete
OpenBSD mirror list here.

First, you need to setup PKG_PATH variable so that you don't have to type complete mirror path each and every time. You need to add file to your shell startup file such as ~/.bashrc or ~/.bash_profile. PKG_PATH variable MUST end in a slash (/).
$ export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/amd64/
OR
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.0/packages/$(machine -a)/

Now to add a package called links:
$ sudo pkg_add -v linksOR # pkg_add -v -i links
Where,

  • -v : Verbose mode (display more information)
  • -i : Interactive installation. It may ask you question such as which version you would like to install and so on.

# pkg_add -i lighttpdOutput:

Ambiguous: lighttpd could be lighttpd-1.4.11 lighttpd-1.4.11-ldap lighttpd-1.4.11-ldap-mysql lighttpd-1.4.11-mysql
Choose one package
         0: 
         1: lighttpd-1.4.11
         2: lighttpd-1.4.11-ldap
         3: lighttpd-1.4.11-ldap-mysql
         4: lighttpd-1.4.11-mysql
Your choice:   1
lighttpd-1.4.11:pcre-6.4p1: complete
lighttpd-1.4.11: complete 

Note that pkg_add prompted for version of lighttpd, you wish to install.

Task: Display or list of OpenBSD installed packages

Use pkg_info command:
$ pkg_infoOutput:

bash-3.1.17         GNU Bourne Again Shell
expat-2.0.0         XML 1.0 parser written in C
gettext-0.14.5p1    GNU gettext
libiconv-1.9.2p3    character set conversion library
lighttpd-1.4.11     secure, fast, compliant, and very flexible web-server
links-0.99          text browser, displays while downloading
pcre-6.4p1          perl-compatible regular expression library
vim-7.0.42-no_x11   vi clone, many additional features
wget-1.10.2p0       retrieve files from the web via HTTP, HTTPS and FTP

Task: Update existing package

To upgrade or update links package type command:
# pkg_add -u links

Task: Update all packages

pkg_add will update all installed packages if no package name is provided:
# pkg_add

Task: Set active or passive mode

If you are behind firewall you may need to set active or passive mode with FTPMODE variable (default is passive).
$ export t FTPMODE=active

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 5 comments… read them below or add one }

1 jman April 10, 2008 at 11:59 pm

Are packages better than ports?
With ports I do – make install clean and it usually sorts out any dependency issues.
But with pkg_add I have had dependency errors.

Reply

2 rob July 8, 2008 at 1:57 am

jman – I prefer to use the packages whenever possible — both pkg_add(1) and the ports methods are capable of determining required dependencies. If you are experiencing specific package dependency issues, I suggest posting on the appropriate OpenBSD mail list.
Those OpenBSD gurus are super-smart and very helpful.

Reply

3 Tommy Chandra W February 24, 2009 at 7:19 pm

very very useful!
thanks for sharing :)

Reply

4 Hendra February 8, 2012 at 1:16 pm

export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.0/packages/i386
I have do that, I want to install unzip, but I can’t. Sorry I’m Indonesian and very very newbie in UNIX.

Reply

5 Sohrab September 9, 2013 at 6:20 am

Thanks for article but “pkg_add” is not working for updating all packages and it returns “pkg_add: Missing pkgname” error.
For doing so, you need to use “pkg_add -u”.

From OpenBSD manual pages:
-u Update the given installed pkgname(s), and anything it depends
upon. If no pkgname is given, pkg_add will update all installed
packages. This relies on PKG_PATH to figure out the new package
names.

Best regards

Reply

Leave a Comment

Previous post:

Next post: