A clean Haskell+Cabal setup for Fedora


Remove all current installs of GHC/Cabal/stack

I imagine you are frustrated with your haskell setup at this point. So, nuke it.

sudo dnf remove ghc cabal-install
rm -rf ~/.ghc ~/.cabal ~/.stack

Download a recent haskell binary distribution

Base URL: https://downloads.haskell.org/~ghc/ Version 8.8.1 (Latest as of this post) https://downloads.haskell.org/~ghc/8.8.1/ For Fedora: https://downloads.haskell.org/~ghc/8.8.1/ghc-8.8.1-x86_64-fedora27-linux.tar.xz

Install GHC

mkdir ~/ghc-installs
cd ~/ghc-installs
mkdir bindists
mkdir tarballs

# Change these as per your params

mv /path/to/ghc-$version-$architecture-$os.tar.xz tarballs
cd bindists
tar -xf ../tarballs/ghc-$version-$architecture-$os.tar.gz
cd ghc-<version>
./configure --prefix=~/ghc-installs/ghc-$version

Install a recent cabal

Base URL: https://www.haskell.org/cabal/download.html For any x86~64~ Linux: https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-

mkdir -p ~/.cabal/bin
cd ~/.cabal/bin
tar -xf /path/to/cabal-install- cabal

Add Cabal to $PATH

add the following line to your ~/.bashrc

export PATH=~/.cabal/bin:$PATH

Get an up-to-date cabal package list

cabal update # Note we still haven't added any ghc to $PATH

Try working with a new haskell package now :)

mkdir test-ghc881
cd test-ghc881

# Create project layout and test-ghc881.cabal
cabal init -w ~/ghc-installs/ghc-$version/bin/ghc

# Create cabal.project.local and fix ghc to it
cabal configure -w ~/ghc-installs/ghc-$version/bin/ghc

# From now on cabal will automatically pick our GHC - not we haven't
# relied on GHC being in $PATH till now. We might just as well use
# another GHC install in ~/ghc-installs/ghc-$otherversion/ for another
# project

cabal build

cabal run # Prints Hello, Haskell!

But wait - it gets better

You can build with another GHC half-way through and cabal maintains separation of build directories for each compiler version

otherversion=8.6.5 # I assume you install it just like you installed ghc-8.8.1
cabal build -w ~/ghc-installs/ghc-$otherversion/bin/ghc
cabal run -w ~/ghc-installs/ghc-$otherversion/bin/ghc

# you can see/run both your builds: