Installing Haskell Platform 2014.2.0.0 on CentOS 6

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

  • you’re running a 64-bit machine and OS installation; I don’t know if this procedure will work in a 32-bit environment,
  • you have sudo access on your machine,
  • you have already installed a basic development environment (gcc, make, and the like); if you haven’t, do yum groupinstall 'Development tools' before beginning the procedure.

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…

set -x
# set some variables, so they're easy to adjust
# 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
# glasgow haskell compiler
# Cabal
# cabal-install
# 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
wget -c${HPVER}/haskell-platform-${HPVER}-srcdist.tar.gz
wget -c${GHCVER}/ghc-${GHCVER}-x86_64-unknown-linux-centos65.tar.bz2
wget -c${CVER}/Cabal-${CVER}.tar.gz
wget -c${CIVER}/cabal-install-${CIVER}.tar.gz
# decompress ghc and install it; we'll need the uncompressed
# ghc tarball when we build the Haskell Platform
tar xjf ghc-${GHCVER}-x86_64-unknown-linux-centos65.tar.bz2
cd ghc-${GHCVER}
./configure --prefix=$BOOTSTRAP
sudo make install
# clean up
/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
/bin/rm -rf Cabal-${CVER}
# decompress and install cabal CLI tool
tar xzf cabal-install-${CIVER}.tar.gz
cd cabal-install-${CIVER}
# clean up (requires root because "sudo" leaves
# root-owned build artifacts lying around)
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}
./ ${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:


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 \

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

  • any build-related files installed into /usr/local
  • /root/.cabal and /root/.ghc
  • ~/.cabal and ~/.ghc
  • any build directories left behind in your $TMPDIR – but you do not have to remove the files the script downloaded prior to beginning the build.

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

Redhat  Linux