Computers & Tech

Pkgsrc – The Unknown Gem

That’s right… I’m going talk tech and specifically talk about package managers. Those who use Linux, Unix or one of the BSDs will definitely understand what I on about.

Anyone familiar with the OpenSource movement and the Unix/Linux approach to managing software, will know that there is really nothing better than typing up a command in a terminal window and having your software automatically installed for you. All the more, it transports you into ‘hacker’ mode as you see all those lines of code; scrolling across your screen like its an 80s/90s hacking movie. Too bad those who are using MacOS can’t have that kind of pleasure.. Or can they?

Meet Homebrew. Powerusers and developers have been using this for a long time.
Homebrew is a package manager for macOS that provides simplified management of software for Apple computers, similar to those found in Linux distributions, such as Ubuntu. I don’t need to go into specific detail about Homebrew.
This opens up a world of software solutions to everyday users that can reap the benefits of using specialized open-source software, currently in production; stuff that you would mostly find in Linux, FreeBSD, etc. & favored by the geeky elite. Homebrew is also not the only one out there for MacOS. There is also MacPorts & Fink.

I thought that those 3 were the only ones for MacOS. The truth is, there are 8 package managers for MacOS – each with their strengths, features and caveats. You can read about them and compare them here… https://www.slant.co/topics/511/~best-mac-package-managers

Homebrew is currently the favorite at the moment. It has a growing number of packages. With its current popularity and heavy reliance on GitHub, most new  Open-Source projects for MacOS will certainly be found on there; sometimes exclusively.
However just because it is popular, does not mean that its the best. Read this..

how Homebrew invites users to get pwned

Anyone who reads the article above will certainly want to use MacPorts. However I have found an alternative – Pkgsrc.
Much like MacPorts, pkgsrc installs its own dependencies and libraries as well as installs it to a specific folder. And it will not install anything without the sudo password. It is quite interesting that I have not heard about it before. It isn’t well known, but rated higher than MacPorts on Slant. While Macports comes in at #5, this comes in at #4..

Pkgsrc originates from NetBSD and other UNIX-like systems and currently containing over 17000 packages. It is used to enable freely available software to be configured and built easily on multiple platforms including BSD, Solaris, Linux and Mac OS. It is well known to Unix / BSD users and maintained by them.
This essentially means that those switching from Linux to MacOS should be able to find their favorite Linux / Unix packages.

It took a few tries to set it up the way I want. If there is no pre-compiled binary, you can just browse the original NetBSD package list and build it from source.. So those who want an easy solution, I recommend MacPorts; or if you don’t care about security, use Homebrew. For those interested in giving Pkgsrc a shot, you can follow my instructions below. This will get you the same setup as me & you will not have any issues.

Step One: – Installing Pkgsrc

*With most package managers you will need to install the “Xcode command line tools” or “Xcode” itself. But for this first step, you won’t any of those. That is one of the good things about pkgsrc. 

You can use the instructions in the following link; in which you will just be ‘copy and paste’ commands to the ‘Terminal’.
http://pkgsrc.joyent.com/install-on-osx/

After this first step you will be able to install all the pre-compiled binaries using the ‘pkgin install’ command or ‘pkg_add’ command.

But what if you want that software that isn’t a binary? For example… ‘finch – a terminal based IM tool’.. That is where the second Step comes in..

Step Two: – Building Packages from Source

** for step 2, you will need to have Xcode and Xcode command line tools installed first. So do that first and then proceed. Once Xcode is installed, you will need to launch the program, Agree to the license, and then let it install its components. Once that is done, you can Quit Xcode. 

With this step, you will be able to browse a full NetBSD ports tree / package list and build the program from source. Note that building from source takes longer than installing a binary. Just copy and paste commands into the terminal (one by one) and press ENTER. Wait for the process to end and then follow with the next:

sudo git clone git://github.com/NetBSD/pkgsrc.git

cd pkgsrc

sudo git remote add joyent git://github.com/joyent/pkgsrc.git

sudo git fetch –all

sudo git checkout joyent/osx/trunk

Finally you will need to edit the ‘/opt/pkg/etc/pkg_install.conf’ and change the line to VERIFIED_INSTALLATION=never

sudo nano /opt/pkg/etc/pkg_install.conf

change “always” to “never” then press CTRL +X and then Y to save it.

You are now ready.. Press Cmd +Shift + H to go to your home directory and you should see pkgsrc there. This is the port collection.

To build a package from source, find the one you want.. go the folder using the terminal. Eg:

cd pkgsrc/misc/tmux

And then use the following command..

sudo bmake install clean

This is very much similar to using the ports system on FreeBSD.

I have been using pkgsrc for a couple of days now, and so far, I like it. The one thing that I like about this gem is that it sort of brings back functionality to MacOS’ BSD/ POSIX core; Darwin. The Unix core was essentially one of the biggest talking points when Mac OS X was introduced back in 2000. In recent years, with all the new features, it seems that many have forgotten about that Unix core; except for developers. More than with any other package manager, with Pkgsrc, I feel I am closer to exploring the possibilities of MacOS’ core and re-uniting it with its BSD relatives; Much like in the book “Call of the Wild”, where a German Shepherd rediscovers its wolf heritage & nature by running with the pack.

Pkgsrc is still new to me and I’m still experimenting with it. Watch this space for a long term review.

Update: (07-Sept-2019)

As of October, 2018, I moved away from Pkgsrc to MacPorts. I was advised to go with Homebrew by many people on the forums, but after reading the article linked above, I am not for it.
Sure, Homebrew gets most of the new packages and probably gets updates faster than MacPorts, but I prefer MacPorts in that it feels quite native to MacOS.

The reason for moving away from Pkgsrc was because I tried installing a couple of packages and only have them fail on me. I tried installing the same using MacPorts and it went through without a hitch. So I’m happy with MacPorts for a while.

I’ve not forgotten about Pkgsrc and having used MacPorts for about a year, it is unlikely that MacPorts will die. But it certainly seems that it is losing traction when compared with Homebrew. My worry is that one day most developers will be forced to move over to brew in the long run and the ports and packages will be left to a handful of maintainers; with many ports going obsolete and outdated.
The one advantage that Pkgsrc has going for it, is that it is a fork of NetBSD. This means that as long as NetBSD will be around, Pkgsrc will too and its packages will be more up to date.

I will be giving Pkgsrc a shot again.

Update: (21-Sept-2019)

I currently have Pkgsrc installed on my system and so far it is going better than last time. In talking with one of the developers (Jonathan Perkin), I’ve come to learn about Pkgsrc; more than what is on the net these days. All those who use Pkgsrc seem to like it, but from some of the reviews most users switched out to MacPorts after a short stint – just like me. One did say that he would be interested in giving a shot again.

The beauty of Pkgsrc is that since it is portable and works on a number of systems, it means that you benefit from all the work developed for all those systems. Pkgsrc works on NetBSD, Haiku and Linux as well as MacOS. According to Jonathan, because of this portability, it really helps with bug fixes, etc. as what fixes something for one OS, most likely fixes it for all the others as well.

Many people who use MacPorts always say that it is like building from source and using the ports on FreeBSD. I would say that it is more like any other package manager on Linux or ‘pkg install’ on the BSDs. Pkgsrc is the best actual clone of the FreeBSD source system. So I would say that if you are coming from the BSDs and you will find it right at home.

In an earlier post, “How Unix is OS X‘, I said that I was willing to dive into the depths of MacOS (then known as OS X) and find out the capabilities of its Unix / POSIX heart. I would say that with Pkgsrc, its a pretty good place to start.

 

Categories: Computers & Tech

5 replies »

    • I would love to say Yes, but sadly I don’t anymore. I’ve been meaning to update this article with my experience with pkgsrc. My biggest complaint with pkgsrc, is that it does not seem as much as home on MacOS as MacPorts is or Homebrew. I tried installing a couple of packages and found that it took too much time before it would fail. This was both the binary and building from source.
      At the moment, I moved over to MacPorts and I’m pretty happy with the results.. It seems much more native and I can see why. Macports was something initiated at Apple by a developer working for them and had Apple’s seal of approval and support for a long time. So its feels and runs far more at home on the system. So that is my pic and recommendation.

      It is not that Pkgsrc is bad. It gets a lot of votes on Slant discussions and at one point is more highly recommended than Macports. But in my experience, your better off with the latter.

    • to get a list of packages on Pkgsrc for Mac use
      pkgin avail

      If you want to know more about pkgsrc for macos.. you will find the info here.
      https://pkgsrc.joyent.com/install-on-osx/

      At the moment, I am currently using Macports and it has everything that I need for now. Plus it was a pleasant surprise to learn that the same person that invented the ports system for FreeBSD is also the same person who helped invent MacPorts. So that is nice piece of BSD heritage there.

Leave a comment