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/

OR.. you can use download the script in this link.. https://github.com/cmacrae/savemacos

Click ‘clone or download’ and then ‘Download ZIP’. It should download to your ‘Downloads’ folder. Look for the folder that says ‘savemacos-master’; open it and double click on the file ‘bootstrap’. Put in your admin password and then wait for it to do its work…

After this first step you will be able to install all the pre-compiled binaries using the ‘plugin 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.

Advertisements

Categories: Computers & Tech

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s