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/
# 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
- -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:
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:
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