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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop










{ 4 comments… read them below or add one }
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.
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.
very very useful!
thanks for sharing :)
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.