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. As a partial test of presense, look for the following files in /usr/include, /usr/lib, /usr/local/include, /usr/local/lib, etc.
name | a.k.a. | a file | remarks |
---|---|---|---|
libbsd | libbsd-dev | libutil.h | |
gmp | libgmp-dev | gmp.h | |
libgmp3c2 | libgmp.so.3 | GHC website binary still wants libgmp.so.3 | |
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-2012.4.0.0) and put one GHC and one Haskell Platform inside. I adjust my PATH environment variable accordingly (add /usr/local/haskell-platform-2012.4.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 |
---|---|
2013.2.0.0 | 7.6.3 |
2012.4.0.0 | 7.4.2 |
2012.2.0.0 | 7.4.1 |
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 or headers, 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 command. What it means: download the list of packages available on Hackage, store it under $HOME/.cabal/packages/hackage.haskell.org.
cabal update
After it finishes, sometimes it suggests:
Note: there is a new version of cabal-install available. To upgrade, run: cabal install cabal-install
Please don't be an enslaved human and obey your computer lord mechanically. This is an informative notice, not a normative order. There is always a catch. (Think: if there were no catch, why would they await your confirmation? Consider who gets the liability.)
The catch: sometimes installing new versions of cabal-install require installing second instances of libraries. Possessing multiple instances of libraries can be confusing, see my article Storage and Identification of Cabalized Packages. See below for preventing multiple instances of libraries.
The command cabal update
you ran also initializes a
configuration file $HOME/.cabal/config. Take some time to review it. In
particular there are some wrong defaults.
-- library-profiling: False ... -- documentation: False
One default says that libraries you install later will not support profiling. Another default says that libraries you install later will not have documentation built. These are the exact opposite of what a programmer needs. Uncomment them and fix them:
library-profiling: True ... documentation: True
Lastly, possessing multiple instances of a library can be confusing, see my
article Storage and Identification of Cabalized
Packages. Unfortunately, the default behaviour of cabal install
is promiscuous and silent in adding multiple instances. Fortunately, since
Haskell Platform version 2012.2.0.0, there is a mechanism to prevent this.
Add these lines at a suitable place in the file, such as near the line
“-- constraint:
”:
(Haskell Platform version
shown. Showing another version requires javascript.)
The idea is to add one line for each package that comes with GHC or Haskell Platform. You may also add lines for other packages—but only after you install them! Do not add a line for a package you don't already have.
I have more Haskell Notes and Examples