Skip to content
Tech News
← Back to articles

Pkgsrc Is Cool (2022)

read original more articles
Why This Matters

This story highlights pkgsrc, a versatile package manager originally from NetBSD, which now supports multiple Unix-like systems. Its ability to build packages from source and keep system environments clean is significant for developers and advanced users seeking more control over their software installations. The article underscores the importance of cross-platform package management and source-based building in the open-source ecosystem.

Key Takeaways

pkgsrc Is Cool

Published: 2021-12-23 22:17:43 -0800 PST

Last updated: 2022-04-24 21:06:24 -0700 PDT

I think I saw something about pkgsrc pop up randomly in my Mastodon feed a few months ago. Before that, I had never heard of it. And now…well now I’m currently writing these words in a version of Emacs that I built from source with pkgsrc.

Pkgsrc is NetBSD’s package manager, but thanks to NetBSD’s portability philosophy, pkgsrc is fully supported as a package manager on other Unix-like operating systems like Linux, Mac, and Solaris. It supports installing binary packages, but the reason I was interested in it is that pkgsrc supports building packages from source as well.

For some context on other similar projects, pkgsrc was originally forked from FreeBSD’s Ports collection decages ago, so for people familiar with the other BSD’s, this is a ports collection that works on other platforms. Even better, pkgsrc and NetBSD get the terminology right and correctly call these things packages instead of ports (and leave “port” as the term for cpu architecture support). Other similar-ish projects include MacPorts, Gentoo’s emerge, GNU Guix, and Ravenports. I probably missed some, but you get the point. There are multiple options out there if you’re interested. I’m not going to compare/contrast them because honestly the only other one I’ve ever used was MacPorts like 10 years ago when I didn’t know what I was doing.

Why did I use it?

I’ve always disliked needing to install a new package to get some program to run. The main reason why is that the new package could pull in other packages and they all end up polluting my system folders like /bin and /lib with extra stuff. Half the time I delete the program I was testing out anyway, but then I’m stuck with this extra stuff in my base system. I never really even stopped to think that there might be way to separate out the “base system” from the other crap I’ve installed along the way.

But this is exactly what NetBSD does. NetBSD’s base system for /bin and such is really only for the core NetBSD system code like the stuff you can build from their source code repo. Anything else is supposed to be installed somewhere else. By default, pkgsrc will install stuff into /usr/pkg where it created its own subdirectory tree of /usr/pkg/bin and /usr/pkg/lib and so on. This way that specfic pkg directory is like a self-contained userland separate from the base operating system. I’m actually using pkgsrc on Debian rather than NetBSD itself, but it works the same way.

Even better, pkgsrc lets you use it in unprivileged mode and install stuff locally in your user’s home directory like ~/pkg . This can give your user their own separate custom userland from other users. Depending on your use case this may not be what you want, but I found it particularly cool that I could run almost a completely separate system just for my user. Because I didn’t want to need sudo/doas to install packages, I am actually using pkgsrc in unprivileged mode with ~/pkg as my base directory.

... continue reading