Skip to content

Instantly share code, notes, and snippets.

@jacobstanley
Created February 16, 2016 23:17
Show Gist options
  • Save jacobstanley/efded8238bc4c64affb7 to your computer and use it in GitHub Desktop.
Save jacobstanley/efded8238bc4c64affb7 to your computer and use it in GitHub Desktop.
Installing Multiple GHC Versions

Installing Multiple GHC Versions

Use these instructions if you want to run multiple versions of GHC side-by-side.

This setup doesn't have GHC on the PATH by default, and uses g to cycle between available versions.

Install GHC 7.8.4

$ wget https://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-x86_64-apple-darwin.tar.xz
$ tar xf ghc-7.8.4-x86_64-apple-darwin.tar.xz
$ cd ghc-7.8.4
$ ./configure --prefix=$HOME/haskell/ghc-7.8.4
$ make install

Install GHC 7.10.2

$ wget http://downloads.haskell.org/~ghc/7.10.2/ghc-7.10.2-x86_64-apple-darwin.tar.xz
$ tar xf ghc-7.10.2-x86_64-apple-darwin.tar.xz
$ cd ghc-7.10.2
$ ./configure --prefix=$HOME/haskell/ghc-7.10.2
$ make install

Zsh

Add the following to your .zshrc:

# List available GHC versions
ghc-list-available() {
  echo "Available versions:"
  for ver in $HOME/haskell/ghc-*; do
    echo "  ${ver##$HOME/haskell/ghc-}"
  done
}

# Switch to a specific GHC version
ghc-switch() {
  if [ -z "$1" ]; then
    echo "USAGE: ghc-switch VERSION"
    ghc-list-available
    return 1
  fi

  VER_PATH="$HOME/haskell/ghc-$1"
  if [ -d "$VER_PATH" ]; then
    export path=($VER_PATH/bin ${(@)path:#*ghc*})
    export GHC_VERSION=$1
    ghc --version
  else
    echo "GHC $1 isn't available"
    ghc-list-available
    return 1
  fi
}

# Cycle GHC versions
g() {
  case $GHC_VERSION in
    7.8.4)
      ghc-switch 7.10.2
      ;;
    *)
      ghc-switch 7.8.4
      ;;
  esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment