Stephen Diehl’s article Vim and Haskell in 2016 does a great job of outlining the quickest way to get a quality Haskell development experience. I ran into a simple issue when I followed it due to a bit of an idiosyncrasy on OS X El Capitan. I also document a few of the extra steps I took which aren’t mentioned explicitly in his original article.
This post wouldn’t actually be necessary if it weren’t for one thing: System Integrity Protection in OS X El Capitan, also known as “rootless” mode. It affects Haskell’s build and install step in a subtle (but solved) way, and the rest of the article will cover what to watch out for when installing on OS X.
If you don’t follow these instructions and you’re on OS X El Capitan, you’ll
likely run into an issue that looks like
/usr/bin/ar: permission denied. The
Stack installation instructions call this out specifically:
If you are on OS X 10.11 (“El Capitan”) or later, GHC 7.8.4 is incompatible with System Integrity Protection (a.k.a. “rootless”). GHC 7.10.2 includes a fix, so this only affects users of GHC 7.8.4.
At the risk of spoiling the surprise, we’re going to set up Stack while taking care to make sure that we get GHC >= 7.10. So let’s do just that!
Environment Prep (optional)
Note that this step is optional and has nothing to do with OS X; I just wanted to point it out quickly.
Times have changed quite a bit, and the new preferred way of installing GHC in 2016 is to forgo using the system package manager for installing ghc and use Stack to manage the path to the compiler executable and sandboxes.
Stack stores it’s metadata in the
~/.stack folder by default. If you’re not a
huge fan of things cluttering up your home folder, set the
in you bashrc or zshrc:
Of course, the choice of location is up to you. In particular I’ve chosen to
adhere to the XDG Base Directory specification here, which you may want
to take a peek at if you’re unfamiliar. That’s why you see references to
Make sure you restart your terminal to pick up the new variables before continuing.
Install Stack from Homebrew
If you’re like me, you’ll want to take a second to purge anything Haskell-related from previous botched setup attempts:
With that out of the way, we can actually get our hands on Stack. For OS X, we’ll install through Homebrew:
Configure Stack, avoiding “rootless” issues
Here’s the trick. We need to run
stack setup for the first time to let Stack
configure itself. But remember: we want to make sure that Stack doesn’t set
itself up with version 7.8.4 of GHC. We can get around this by specifying an
explicit resolver to the
stack command (you can find more information on
You’ll notice we use the
--resolver=... flag to force Stack to use a specific
resolver. This post will be out of date as soon as it’s written, so check
Stackage to find the latest LTS snapshot.
Return to Vim and Haskell in 2016
That’s it for the environment setup! Now you’ll want to turn your attention to configuring Vim.
The steps to set up Vim are platform independent, so now that we’ve set up Stack correctly, you can head over to Vim and Haskell in 2016 to finish things out.