Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing GHC 7.2 on Mac OS X 10.7 Lion

Installing GHC 7.2 on Mac OS X

This is a brief and bare-bones guide to getting GHC 7.2 and the cabal-install tool (the two basic things you'll need to do Haskell development) up and running on a new Mac OS X 10.7 install.

The instructions given here worked for me, but YMMV.

Installing GHC

Downloading and installing GHC 7.2.1 for x86_64 (Darwin) is straightforward.

curl -O
tar -xjvf ghc-7.2.1-x86_64-apple-darwin.tar.bz2
cd ghc-7.2.1
make install

Installing cabal-install

Downloading, patching and installing the latest version of the cabal-install tool is not quite so easy, but won't take long if you're careful (and you don't run into problems that I didn't).

Patching is required because cabal-install 0.10.2 has a very conservative dependency list and many of the core packages included with GHC 7.2 have version numbers greater than many of the upper bounds given by cabal-install's .cabal file.

cd -
curl -O
tar -xzvf cabal-install-0.10.2.tar.gz
cd cabal-install-0.10.2
curl -O
patch -p0 cabal-install.cabal ghc7.diff

The script is provided by cabal-install as an easy way to get cabal-install and all its dependencies up and running. However, it needs some changes to work under GHC 7.2.

GHC 7.2 removes the random package from the distribution, so we need to modify and have it install along with zlib, HTTP and the rest. We also need to update the list of packages to install to use more recent versions which will build under GHC 7.2.

Replace the whole block of version numbers and regexps with these new ones:

PARSEC_VER="3.1.1";    PARSEC_VER_REGEXP="[23]\."     # == 2.* || == 3.*
NETWORK_VER=""; NETWORK_VER_REGEXP="2\."       # == 2.*
CABAL_VER="1.12.0";    CABAL_VER_REGEXP="1\.12\.[^0]" # == 1.10.* && >= 1.10.1
TRANS_VER="";   TRANS_VER_REGEXP="0\.2\."      # == 0.2.*
MTL_VER="";     MTL_VER_REGEXP="[12]\."        # == 1.* || == 2.*
HTTP_VER="4000.1.2";   HTTP_VER_REGEXP="4000\.[01]\." # == 4000.0.* || 4000.1.*
ZLIB_VER="";    ZLIB_VER_REGEXP="0\.[45]\."    # == 0.4.* || ==0.5.*
TIME_VER="";    TIME_VER_REGEXP="1\.[12]\."    # == 0.1.* || ==0.2.*
RANDOM_VER="";  RANDOM_VER_REGEXP="1\."        # == 1.*

Then add the following lines next to their kin:

info_pkg "random"       ${RANDOM_VER}  ${RANDOM_VER_REGEXP}

do_pkg   "random"       ${RANDOM_VER}  ${RANDOM_VER_REGEXP}

Since the Cabal library comes with GHC, we also don't need it installed by the bootstrap script, so find the following two lines and comment them out:

# info_pkg "Cabal"        ${CABAL_VER}   ${CABAL_VER_REGEXP}

# do_pkg   "Cabal"        ${CABAL_VER}   ${CABAL_VER_REGEXP}

We want cabal-install and its dependencies to be installed globally, as though they were being installed by something like the Haskell Platform, so the final change to is to change the installation scope from --user to --global. You can skip this step if you prefer to install cabal-install and its dependencies locally.


Finally, run the bootstrap script to install cabal-install.


That should be it. Happy hacking!

Copy link

beastaugh commented Aug 26, 2011

@lidavidm: happy to hear it. I may try it myself on an Ubuntu VM. Obviously it would be better if all these hacks weren't needed, but as GHC 7.2 is so new it's to be expected that not every package has been updated to work with it yet. Hopefully tickets like this one will be resolved sooner rather than later…

Copy link

jniva commented Aug 30, 2011

That's good for it! THANKS a lot!

Copy link

davdar commented Sep 4, 2011

Thank you SO much. Life saver.

Copy link

alvivi commented Sep 7, 2011

I'm still having lots of "ld: warning: text reloc in [...]" messages with GHC 7.2 and Lion. Any solution?

Thank you.

Copy link

mcandre commented Sep 7, 2011

Very illuminating. But why not just use Haskell Platform?

Copy link

beastaugh commented Sep 7, 2011

@mcandre because the version of GHC that comes with the Platform doesn't work properly on OS X 10.7.

Copy link

beastaugh commented Sep 7, 2011

@alvivi are you sure you're using GHC 7.2.1? That fixed all the linker warnings for me. Maybe talk to Manuel Chakravarty? I know he was the person patching the problems with OS X and GHC.

Copy link

itkovian commented Sep 12, 2011

That would be "tar -xjvf ghc-7.2.1-x86_64-apple-darwin.tar.bz2" :-)

Copy link

beastaugh commented Sep 12, 2011

@itkovian quite right, thanks.

Copy link

ijt commented Oct 2, 2011

The configure step fails for me with

configure:2906: checking for C compiler default output file name
configure:2933: /Developer/usr/bin/gcc conftest.c >&5
ld: library not found for -lcrt1.10.6.o
collect2: ld returned 1 exit status

Update: This happened because I forgot to run the Xcode installer. The app store makes it look like Xcode is installed, when in reality only the installer is installed.

Copy link

beastaugh commented Oct 2, 2011

Looks like it's selecting the wrong C compiler: /Developer/usr/bin/gcc is symlinked to llvm-gcc-4.2, not the actual gcc-4.2. You are using OS X 10.7 and Xcode 4, yes?

Copy link

mcandre commented Oct 2, 2011


Copy link

JakubOboza commented Dec 10, 2011

Configuring Cabal-
Setup: At least the following dependencies are missing:
base >=4 && <3 && >=2 && <5, unix >=2.0 && <2.5

Error during cabal-install bootstrap:
Configuring the Cabal package failed

I'm sad

Copy link

deepakjois commented Jan 26, 2012

It looks like the patch for cabal-install is not available for download any more. I found this gist which contains the same patch, but needs git to apply it.

% curl -O
% cat cabal-install-ghc722.patch | git apply

Copy link

beastaugh commented Jan 27, 2012

@deepakjois thanks, I'll try to find some time over the weekend to update the instructions. I'll probably just rewrite it to work with the GHC 7.4 release candidate since that's both newer and actually intended as a publicly releasable version, not just a technology preview like GHC 7.2 is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment