Skip to main content.

Ports and packages in OpenBSD

2014-06-04

Live demo in BSD Now Episode 040 | Originally written by TJ for bsdnow.tv | Last updated: 2014/11/01

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

Like most of the other BSDs, OpenBSD supports multiple ways of installing third party software. Both their ports and package systems were originally taken from FreeBSD, but have since changed quite a bit. If you're familiar with the FreeBSD versions, you'll notice a lot of similarities, but also some interesting differences. Both ways make it really easy to install, remove and update programs that you may want to add to the base system. OpenBSD handles port branches a bit differently. There are -current and -stable branches that get security updates, and the -release branch which is frozen before a release every six months. You can (and should) run the -stable branch of ports on either a -release or -stable system, but the -current branch will only work on -current. Things must be kept in sync with the base system version. It's recommended to properly set up sudo instead of using the root account, and the FAQ has instructions for that. To get your initial copy of the ports tree, you can either download the -stable tree directly via CVS like so:

# cd /usr
# cvs -qd anoncvs@anoncvs.usa.openbsd.org:/cvs get -rOPENBSD_`uname -r | sed 's/\./_/'` -P ports

Or grab the -release distribution and then update it:

# cd /usr
# ftp http://ftp.usa.openbsd.org/pub/OpenBSD/`uname -r`/ports.tar.gz
# ftp http://ftp.usa.openbsd.org/pub/OpenBSD/`uname -r`/SHA256.sig
# signify -C -p /etc/signify/openbsd-`uname -r | cut -c 1,3`-base.pub -x SHA256.sig ports.tar.gz

Signature Verified
ports.tar.gz: OK

# tar xzf ports.tar.gz
# rm ports.tar.gz SHA256.sig
# cd ports
# cvs -d anoncvs@anoncvs.usa.openbsd.org:/cvs -q up -rOPENBSD_`uname -r | sed 's/\./_/'` -Pd

Be sure to choose a mirror that's close to you for better speeds. OpenBSD's -stable ports tree is frozen on a per-version basis, other than for security updates or important fixes. This means that you can't get the latest version of a port if it's been committed to the -current tree but didn't make it in time for the release. If you want a "rolling release" style system like FreeBSD ports, you have to run -current. Now that we have an up to date -stable ports tree, we can begin installing software.

# cd /usr/ports/www/newsbeuter
# make install BULK=Yes

And that's all there is to it. The source code will be fetched, patched and compiled into a binary package for you. The resulting packages are in /usr/ports/packages and can be reused on other systems. Some ports offer different flavors and subpackages you can choose from. We'll use vim as an example here.

# cd /usr/ports/editors/vim
# make show=FLAVORS

huge gtk2 athena motif no_x11 perl python python3 ruby

Each of these are different flavors of the port you can use. Obviously I don't want any of those useless options, so I'll choose the sensible version like so:

# env FLAVOR="no_x11" make install

And it will be built as usual. For a subpackage, it's very similar:

# cd /usr/ports/net/pidgin
# make show=MULTI_PACKAGES

-main -finch -libpurple

# env SUBPACKAGE="-finch" make install

If you'd rather install from a binary package, you could do so like this:

# export PKG_PATH=http://ftp.usa.openbsd.org/pub/OpenBSD/`uname -r`/packages/`arch -s` 
# pkg_add vim

Ambiguous: choose package for vim
 a       0: <None>
         1: vim-7.4.135p0-gtk2
         2: vim-7.4.135p0-gtk2-perl-python-ruby
         3: vim-7.4.135p0-gtk2-perl-python3-ruby
         4: vim-7.4.135p0-no_x11
         5: vim-7.4.135p0-no_x11-perl-python-ruby
         6: vim-7.4.135p0-no_x11-perl-python3-ruby
Your choice: 

You can select which version you want to install very easily this way too. Multiple packages can be specified at once with pkg_add. You can export the PKG_PATH variable in your ~/.profile or /etc/pkg.conf so you don't have to type it every time. If you'd like to install multiple ports at once, you may be interested in using dpb for that. To list all the ports/packages you currently have installed (there's no difference once they are installed) you can run:

# pkg_info

cowsay-3.03             speaking ascii cow
dnscrypt-proxy-1.3.3p0  secure communications between a DNS client and resolver
mutt-1.5.22p0v0         tty-based e-mail client, development version
newsbeuter-2.7          open-source RSS/Atom feed reader for text terminals
rsync-3.1.0-iconv       mirroring/synchronization over low bandwidth links
vim-7.4.135p0-no_x11    vi clone, many additional features

Searching the ports tree is also really simple.

# cd /usr/ports
# make search key=vnstat

Port:   vnstat-1.11p6
Path:   net/vnstat
Info:   network traffic monitor
Maint:  Pierre-Emmanuel Andre <pea@openbsd.org>
Index:  net sysutils
L-deps: graphics/gd
B-deps: devel/gmake
R-deps: 
Archs:  any

To update your -stable ports tree, run:

# cd /usr/ports
# cvs -d anoncvs@anoncvs.usa.openbsd.org:/cvs -q up -rOPENBSD_`uname -r | sed 's/\./_/'` -Pd

Note that the -d option is only needed if you got your tree from the ports.tar.gz file. If you initially got it from CVS, you can omit that part and just run:

# cd /usr/ports
# cvs -q up -rOPENBSD_`uname -r | sed 's/\./_/'` -Pd

You can check which of your ports are out of date by running a script that's included with the ports collection.

# /usr/ports/infrastructure/bin/out-of-date

Collecting installed packages: ok
Collecting port versions: ok
Collecting port signatures: ok
Outdated ports:

devel/quirks                   # always-update -> quirks-1.113
graphics/cairo                 # @png-1.6.8 -> @png-1.6.8p0
graphics/gdk-pixbuf2           # @png-1.6.8 -> @png-1.6.8p0
graphics/imlib2                # @png-1.6.8 -> @png-1.6.8p0
graphics/png                   # 1.6.8 -> 1.6.8p0
www/firefox-esr                # 24.3.0 -> 24.5.0

Upgrading a port is as easy as running the following in the port directory:

# cd /usr/ports/graphics/png
# echo 'FETCH_PACKAGES=Yes' >> /etc/mk.conf
# make update

The FETCH_PACKAGES variable will tell ports to install build dependencies from binary packages, so you only have to compile the port that actually needed updating. To update all your binary packages at once:

# pkg_add -u

But this assumes the mirror you set as your PKG_PATH has updated packages. The official mirrors do not. Uninstalling something is as simple as:

# pkg_delete vim

If you've built something from ports and want to remove all the build dependencies, or just want to clean up a system after uninstalling something, run:

# pkg_delete -a

It will remove all the orphaned packages that are no longer required. It's worth noting that OpenBSD does not provide security updates for packages outside of -current, so you will need to use ports for security fixes. If you have a lot of machines to update, the previously-mentioned dpb tutorial will be very useful. Since there usually aren't many updates between -release and -stable ports, you may want to save some time and just install everything from packages. Be sure to check if there have been any fixes committed to the -stable branch that affect you, though. Two handy sites for searching the ports tree online are ports.su and openports.se. Additional configuration can be done with the /etc/mk.conf file.

Latest News

New announcement

2017-05-25

Hi, Mr. Dexter...

Two Year Anniversary

2015-08-08

We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment

2015-01-17

We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?

2014-11-26

We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...


Episode 210: Your questions, part I

2017-09-06

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines A Reimplementation Of Netbsd Using a Microkernel Minix author Andy Tanenbaum writes in Part 1 of a-reimplementation-of-netbsd-using-a-microkernel Based on the MINIX 3 microkernel, we have constructed a system that to the user looks a great deal like NetBSD. It uses pkgsrc,...

Episode 209: Signals: gotta catch ‘em all

2017-08-30

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Trip Report: FreeBSD in China at COPU and LinuxCon This trip report is from Deb Goodkin, the Executive Director of the FreeBSD Foundation. She travelled to China in May 2017 to promote FreeBSD, meet with companies, and participate in discussions around Open...

Episode 208: Faces of Open Source

2017-08-23

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines LLVM, Clang and compiler-rt support enhancements In the last month I started with upstream of the code for sanitizers: the common layer and ubsan. I worked also on the elimination of unexpected failures in LLVM and Clang. I've managed to...

Episode 207: Bridge over the river Cam

2017-08-16

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines BSDCam recap The 2017 Cambridge DevSummit took place from 2-4 August 2017. The event took place over three days including a formal dinner at St John's College, and was attended by 55 registered developers and guests. Prior to the start of...