Doing GNU/Linux on a Mac

I like to work in multiple operating systems, partly because some things are much easier in one OS than others (and some things are only available in one OS), and partly because I like the way it gives me a broader idea of what computing is about, in the same way that I imagine being properly multilingual would give you a broader idea of what language is. And if I were properly multilingual I might not write such dreadful run-on sentences.

Most of the time I work on Macs, because one of the things I particularly like about them is that they’re very shiny, visual and easy to use on top … but underneath it’s basically  POSIX-compliant BSD Unix, so you can do the full-on GNU/Linux command line thing properly if that’s the best way to get a job done. Historically, one of the big drawbacks of Unix-related stuff – and legendarily GNU – was that getting hold of a new bit of software and making it work on your machine could be a bit … involved. Especially when to get X working you had to install Y and Z, and Z required P and Q, which both require Y, and so on. Never mind keeping it all up to date. But modern package managers do a great job of making it much, much simpler.

Alas, the Mac doesn’t come with a package manager – Macs have their own (generally much more user-friendly) way of installing software, which doesn’t work for GNU/Linux software. Happily, there are several ways of dealing with this.

cc licensed ( BY ) flickr photo shared by Steve Evans

This post is a techie log of what I did to make a Mac work a bit more like a GNU/Linux machine at the command line, for my own reference (I’m expecting to have to do this again soonish), and for anyone running in to the same problems I did.

My proximal goal was getting Image Magick (for some image tweaking) and Octave (for a Coursera Machine Learning MOOC) working, and several other useful bits and pieces, on an iMac running Mac OS X 10.7.5 Lion.

There are three main choices for package managers on a Mac: MacPorts, Fink and Homebrew. I’ve previously used MacPorts but had problems here and there that were too much bother to fix. But based on this useful StackExchange post on the pros/cons of MacPorts, Fink and Homebrew, some personal recommendations, and realising that the whole ‘it all (looks like it) lives in /usr/local’ approach made sense in my muddled old-school head in a way the other approaches hadn’t, and very much liking to minimise the use of sudo and root on principle, I decided to go with Homebrew.

Before doing any of that, I installed XCode, which you need for doing anything involving compilation on a Mac. Easiest way (for me) was the free install from the App Store. Once installed, start XCode, go to Preferences, then the Components tab, and install ‘Command Line Tools’. C was my first proper programming language (which you can probably tell if you ever catch sight of my code in any other language I try to write in), so I banged out a quick hello.c (with cat, so I could feel properly old school) and make hello and it worked fine.

Then it was time for Homebrew. The simple install:

ruby -e "$(curl -fsSL"

didn’t work for me – I got:

curl: (7) couldn't connect to host

I guessed this was a proxy problem for curl (I’m behind one on this machine), so I created a .curlrc in my home directory (~) with the single line:


Then the install worked fine. Checking with

brew doctor

gave me this warning:

Warning: You have a curlrc file
 If you have trouble downloading packages with Homebrew, then maybe this
 is the problem? If the following command doesn't work, then try removing
 your curlrc:

Well, for me not having a curlrc gave me problems downloading packages, so never mind that. (And trying curl worked fine and showed me the 301 Moved Permanently error which points you over to the https version.)

Installing ImageMagick then worked perfectly well with a simple:

brew install imagemagick

… which was very nice, and just the thing I wanted to be able to do. But trying Octave like this:

brew install octave

failed with:

Error: No available formula for octave

There were actually two problems here. I tried a few other packages to install and got the same. So I tried

brew update

and got

Initialized empty Git repository in /usr/local/.git/
error: Failed connect to; Connection refused while accessing
fatal: HTTP request failed
Error: Failure while executing: git fetch origin

Aha! I thought. Git is having proxy troubles too. That was the first problem. So I did:

git config --global http.proxy

and then ‘brew update’ worked fine, doing plenty of work.

For Octave, following this article ( I did

brew install fltk

(I tried ‘brew install –HEAD fltk’ first but got ‘Error: No head is defined for fltk’ – which I fear may lead to trouble down the line.)

and then

brew install --with-magick-plus-plus GraphicsMagick

which both worked fine. In retrospect I might’ve got away without these two steps. The second problem is that Octave lives in the homebrew/science set of formulae, not the defaults, so I then did

brew tap homebrew/science

to include the homebrew/science library, then

brew install homebrew/science/octave

which did fine, merrily downloading and building things, until it complained that it needed a Fortran compiler. A Fortran compiler! In 2013! Actually that makes perfect sense, since some of the heavy-lifting numerical algorithms in Octave are written in Fortran. (And it started life as a project so engineering students could learn about doing numerical computation without having to learn Fortran.) Homebrew very helpfully suggested, and I went along with:

brew install gfortran

which worked fine, so I did

brew install homebrew/science/octave

again. Which then installed all the way without problems. Then I did

brew install gnuplot

… on the grounds that that it was probably needed for plotting. Octave started and simple sums seemed to work fine. But when I tried to produce a plot (from my course), I got:

gnuplot> set terminal aqua enhanced title "Figure 1" size 560 420  font "*,6"
         line 0: unknown or ambiguous terminal type; type just 'set terminal' for a list

Another known problem with a known fix: I created a .octaverc in my home directory (~) with the single line:


… ran Octave again, and all was well.

I’m not sure whether you need to install X11 manually or not these days (I suspect not) – you need it for Gimp, and I’d already installed that. There doesn’t seem to be an official Homebrew formula for Aquaterm (to get more Mac-native-looking plots), and Aquaterm seems quasi-abandoned since mid-2011, but it might be worth trying (maybe: uninstall gnuplot with brew uninstall gnuplot, install Aquaterm with the dmg, then brew install gnuplot again and remove the .octaverc diverting it to X11. But reading a bit of the Aquaterm mailing list about needing to recompile to get plot widths beyond 1000px wide suggested X11 will do fine for now.

Easy when you know how!

This work by Doug Clow is copyright but licenced under a Creative Commons BY Licence.
No further permission needed to reuse or remix (with attribution), but it’s nice to be notified if you do use it.

Author: dougclow

Experienced project leader, data scientist, researcher, analyst, teacher, developer, educational technologist and manager. I particularly enjoy rapidly appraising new-to-me contexts, and mediating between highly technical specialisms and others, from ordinary users to senior management. After 20 years at the OU as an academic, I am now a self-employed consultant, building on my skills and experience in working with people, technology, data science, and artificial intelligence, in the education field and beyond.