Sunday, May 3, 2009

Install Cabal with Ubuntu 9.04 Jaunty and GHC 6.8.2 or 6.10.1

Cabal is a marvelous help to install the Haskell packages found in Hackage. There is a very long and rapidly increasing list of Haskell packages to solve nearly any programming task collected in Hackage: reading XML files, connecting to databases, to graphical user interface (wx) or to run a web server – all this and much more is available. The only problem was to find the right versions to work together, such that the ghc package manager is satisfied and the result is running.

The regular method to install packages was:
  1. find the package on Hackage

  2. unpack the file in a directory of your choice

  3. change into this directory

  4. runghc or runhaskell Setup.hs configure (or Setup.lhs – whatever is in the package)

  5. runghc or runhaskell Setup.hs build

  6. sudo runghc or sudo runhaskell Setup.hs install
    With this command, the compiled content is moved to /usr/local/lib and registered with the package manager of ghc (in /usr/lib/ghc-6.8.2)
  7. download the package as a .tar.gz file (link at the bottom of the page)

The procedure is simple, but time consuming to satisfy the dependencies between packages. A package may need another packages that must be previously installed, which is discovered in step 5 (configure). Then the package required must be installed first; it is usually easy to find on the hackage page of the dependent package, but may require yet another package...

Cabal automates this. The only problem was that I could not find a ready made cabal-install program and had to construct it. I had a new and clean installation for GHC 6.8.2 in Ubuntu 9.04 Jaunty (and the same should apply for Ubuntu 8.04 Hardy and 8.10 Intrepid). I loaded a bunch of packages already available in the Ubuntu repository, of which libghc-network, libghc6-parsec and libghc6-zlib (with the dependent zlib...) are likely the only relevant ones here.

The blog gave me a start, but I ran into problems with cabal-install-0.6.2 as described there, probably because I had a 6.8.2 ghc and difficulties to build network, which I could not download. I gave up with ghc 6.10 which is not yet available for ubuntu.

I tried first to use the traditional method to install cabal-install, but found later a simpler method:

  1. getting cabal-install-0.6.0 from hackage and use
  2. sudo sh

Required are the packages mtl, parsec and network, which I had. The result is an executable ~/.cabal/bin/cal, which I copied to /usr/bin (sudo cp ~/.cabal/bin/cabal /usr/bin). Next, it may be necessary to run cabal update to download the list of packages from hackage.

Now life should be wonderful! (I did just install WxGeneric with simply sudo cabal install WxGeneric...)

Alternatively and on a different computer, the traditional approach with manual download and configure/build/install worked for the combination

  1. HTTP 3001.0.4 (produces some warnings)
  2. Cabal 1.2.3
  3. cabal-install 0.4.0

Higher versions I could not get working – but the result is satisfying.

Later note for installation with 6.10.1:

I installed manually only parsec- and network- (with runhaskell Setup.hs configu/build/install) and then the ./bootstrap script in cabal-install-0.6.2 ran.


  1. Thank you, I finally could install wxHaskell thanks to your tutorial!

  2. now the same with ubuntu 9.10 Karmic Koala and ghc 6.10.4:
    install cabal by first download the files from the page. then run the bootstrap file in a terminal:
    1. cd to directory where the downloaded files are.
    2. ./
    you get error messages about packages which are missing - install them with synaptic (search for libghc-PACKAGE_NAME).
    typically needed network, parsec, http
    3. copy the cabal from you ~/.cabal/bin to (for example) /usr/bin

    i use now primarily gtk (partially to avoid the difficulty to install wx)