Why you may like to build Haskell Platform from source: there is no binary package for your OS; there are binary packages for your OS but you don't like them (versions, directories, privileges). (If you have none of those problems, good for you!)
This article is for Unix-like OSes, generalizing from what works on Ubuntu Linux.
Haskell Platform and GHC rely on some C libraries. You need them and their
headers present to build Haskell Platform, not to mention use. As a partial
test of presense, look for the following header files in
/usr/include, /usr/local/include, etc.
| name | a.k.a. | a header file | remarks |
|---|---|---|---|
| editline | libedit-dev | histedit.h | only for Haskell Platform 2009.2.0.2 |
| libbsd | libbsd-dev | libutil.h | |
| gmp | libgmp3-dev | gmp.h | |
| zlib | zlib1g-dev | zlib.h | |
| GLUT | freeglut3-dev | GL/glut.h | also OpenGL, X... too many to list but your package manager likely gets them all from GLUT |
By default, Haskell Platform files will be scattered over various places in /usr/local. Same story for GHC if you install it yourself.
You may dislike this for one of two reasons. When you want to delete files, they are harder to hunt down. If you want several versions of Haskell Platform or GHC to co-exist, they step over each other in /usr/local/bin (Haskell Platform contains executables too).
How I do it: I create one directory (say /usr/local/haskell-platform-2011.2.0.0) and put one GHC and one Haskell Platform inside. I adjust my PATH environment variable accordingly (add /usr/local/haskell-platform-2011.2.0.0/bin). Switching versions means just editing PATH. You could further separate GHC and Haskell Platform into two directories if you want.
You must install GHC yourself to build Haskell Platform from source. While binary packages of Haskell Platform include GHC, the source does not. Any means of installing GHC is fine:
If your OS promotes a GHC package and it is the right version, you may use it. (Or it is not quite the right version but you take the risk.)
Alternatively, you may choose a binary tarball from the GHC website. (There are links in the table below.) Beware that the website will say
Ignore it and go ahead to find a binary tarball.
(The website advice would be right for Haskell Platform binary installers, which come with GHC. But you have just understood that the source doesn't, right?)
Unpack the binary tarball and change directory into the unpacked. Then
./configure --prefix=chosen-directory make install
You may build GHC from source, but this requires GHC. To understand recursion…
(In case you do, you should watch a movie while it builds. I recommend the Ten Commandments, Ben-Hur, the Robe, Cleopatra, the King and I, the Sound of Music, Fantasia… in general, a movie so long it actually contains an intermission.)
You may ask a friend to do it.
You may buy a computer with GHC pre-installed…
There is a matching version of GHC for each version of Haskell Platform, and it is seldom the “current released” version. Normally you should stick to the matching version of GHC; the benefits are that the matched pair has been well-tested together and is well-supported. Using a slightly older or newer GHC is possible but slightly more risky.
| Haskell Platform version | GHC version |
|---|---|
| 2011.4.0.0 | 7.0.4 |
| 2011.2.0.1 | 7.0.3 |
| 2011.2.0.0 | 7.0.2 |
| 2010.2.0.0 | 6.12.3 |
| 2010.1.0.0 | 6.12.1 |
| 2009.2.0.2 | 6.10.4 |
Look for “Build from source” and get the .tar.gz file on “Haskell Platform for Linux”.
Unpack and change directory into the unpacked.
Configure with:
./configure --prefix=chosen-directory
If you lack some C libs, it tells you now.
If you use a mismatched GHC, it also finds out now, and you can insist with
./configure --prefix=chosen-directory --enable-unsupported-ghc-version
If there is no problem so far, you can build now, and it will take 5-10 minutes:
make
If it builds successfully, you can install now, and this needs enough privilege:
make install
When it finishes, it instructs you to initialize “the package list” with the following. What it does: downloads and caches the list of libs available on Hackage.
cabal update
I have more Haskell Notes and Examples