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. His post presumes Ubuntu; here we presume OS X.
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:
1 2 3 4
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:
1 2 3 4 5 6 7 8
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
1 2 3 4
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.
Jake on the Web
If you cared enough to read that far, you should consider following me on GitHub or paying a visit to my homepage. If this post was about one of my open source projects, make sure to star it on GitHub! I love hearing what people think, so feel free to comment, open an issue, or send me an email.