Installing Haskell Platform 2014.2.0.0 on CentOS 6

By Paul Heinlein | Oct 7, 2014

I was recently asked to assist someone install the newest Haskell Platform on a CentOS 6 machine. Mind you, the point of the Haskell Platform releases is to make it easier to get a complete Haskell development environment. I suppose it’s easier if you’re running a Linux distribution for which there are pre-built Haskell Platform binary releases. CentOS 6 is not one of those favored distributions, however, and the procedure was much, much harder than it should have been.

The work that needs to be done is essentially a series of shell commands, so the bulk of this post is the bash script that successfully completed all the required commands, but I need to spell out a few caveats up front. The script assumes

One final caveat: the script doesn’t do any error checking; it’s certainly not meant for production. I’d suggest watching it very carefully as it runs.

Without further ado, the script…

#!/bin/sh
set -x
  
# set some variables, so they're easy to adjust
TMPDIR=/var/tmp
BOOTSTRAP=/usr/local/hp-bootstrap
  
# these versions are current as of oct 3, 2014. if a lot of time has
# passed between then and the time you build this, you might want to
# verify they haven't been superseded by newer versions.
  
# haskell platform
HPVER="2014.2.0.0"
# glasgow haskell compiler
GHCVER="7.8.3"
# Cabal
CVER="1.20.0.2"
# cabal-install
CIVER="1.20.0.3"
  
# make sure some prerequisites are installed
RPMPKGS="gmp-devel mesa-libGL-devel mesa-libGLU-devel freeglut-devel"
rpm -q $RPMPKGS >/dev/null 2>&1 || sudo yum install $RPMPKGS
  
# grab the necessary archives
cd $TMPDIR
wget -c https://www.haskell.org/platform/download/${HPVER}/haskell-platform-${HPVER}-srcdist.tar.gz
wget -c http://www.haskell.org/ghc/dist/${GHCVER}/ghc-${GHCVER}-x86_64-unknown-linux-centos65.tar.bz2
wget -c http://www.haskell.org/cabal/release/cabal-${CVER}/Cabal-${CVER}.tar.gz
wget -c http://www.haskell.org/cabal/release/cabal-install-${CIVER}/cabal-install-${CIVER}.tar.gz
  
# decompress ghc and install it; we'll need the uncompressed
# ghc tarball when we build the Haskell Platform
cd $TMPDIR
tar xjf ghc-${GHCVER}-x86_64-unknown-linux-centos65.tar.bz2
cd ghc-${GHCVER}
./configure --prefix=$BOOTSTRAP
sudo make install
  
# clean up
cd $TMPDIR
/bin/rm -rf ghc-${GHCVER}
  
# put ghc in your PATH; we'll also use this path for cabal
# later on
export PATH=${BOOTSTRAP}/bin:$PATH
  
# decompress and install the Cabal library
tar xzf Cabal-${CVER}.tar.gz
cd Cabal-${CVER}
ghc -threaded --make Setup
./Setup configure --prefix=$BOOTSTRAP
./Setup build
sudo PATH=${BOOTSTRAP}/bin:$PATH ./Setup install
  
# clean up
cd $TMPDIR
/bin/rm -rf Cabal-${CVER}
  
# decompress and install cabal CLI tool
tar xzf cabal-install-${CIVER}.tar.gz
cd cabal-install-${CIVER}
sudo PATH=${BOOTSTRAP}/bin:$PATH PREFIX=$BOOTSTRAP ./bootstrap.sh --global
  
# clean up (requires root because "sudo bootstrap.sh" leaves
# root-owned build artifacts lying around)
cd $TMPDIR
sudo /bin/rm -rf cabal-install-${CIVER}
  
# run cabal update and install hscolour
sudo PATH=${BOOTSTRAP}/bin:$PATH ${BOOTSTRAP}/bin/cabal update
sudo PATH=${BOOTSTRAP}/bin:$PATH ${BOOTSTRAP}/bin/cabal install --global hscolour
  
# get rid of .cabal in root and build users home directory
sudo /bin/rm -rf /root/.cabal
/bin/rm -rf ${HOME}/.cabal
  
# decompress and install the Haskell Platform; this step may take
# a LONG time to complete, depending on the CPU and RAM available
tar xzf haskell-platform-${HPVER}-srcdist.tar.gz
cd haskell-platform-${HPVER}
./platform.sh ${TMPDIR}/ghc-${GHCVER}-x86_64-unknown-linux-centos65.tar.bz2

Assuming success, you’ll end up with a compressed tar archive called haskell-platform-2014.2.0.0-unknown-posix-x86_64.tar.gz buried in the bowels of your Haskell Platform build directory. The build script will tell you where exactly it’s located. When you’re ready to install it, simply (as root) untar it from the root (/) directory and run the activation script:

/usr/local/haskell/ghc-7.8.3-x86_64/bin/activate-hs

Once that’s done, you’ll have a bunch of symlinks in /usr/local/bin for ghc and other haskell tools.

Before you untar and activate your shiny new Haskell Platform, you may want to clean up a bunch of the files the build process left behind in /usr/local. On my system, I had to delete the HsColor binary and several directory trees:

/bin/rm -rf \
  /usr/bin/HsColor \
  /usr/local/hp-bootstrap \
  /usr/local/share/x86_64-linux-ghc-7.8.3 \
  /usr/local/share/doc/x86_64-linux-ghc-7.8.3 \
  /usr/local/lib/x86_64-linux-ghc-7.8.3

If for some reason the build script fails and you need to restart, I’d suggest deleting several things before trying again:

I haven’t explored all the intricacies of the problem, but some compile steps will fail unless you’re working in a clean environment.