Install ghc-mod with GHC 8.2.2 on Linux

Posted onby

With stacks ghc version 8.2.2 it is not easy to install ghc-mod with stack. The reason are not matched dependencies. With a small trick we can install ghc-mod by building it ourselves. In this blog post you will learn how to do so. Let's get started.


  • git is installed on your machine
  • stack is installed on your machine

First of all, where can we find ghc-mod sources? The right repository for this is the ghc-mod repository on GitHub. In his blog post we will clone it, adapt a stack.yaml file and then build and install the ghc-mod binary.

Step 1

Let's prepare our build. Since we don't want to keep the source (if you would like to do different, feel free to copy the files anywehere you like), we will create a temporary folder and switch to it:

mkdir -p /tmp/build
cd /tmp/build

Step 2

For the second step, let's checkout the repository with the correct sources and change the directory:

git clone https://github.com/DanielG/ghc-mod.git -b ghc802
git clone https://github.com/DanielG/cabal-helper.git
cd ghc-mod

Step 3:

To build the ghc-mod with stack we need a valid stack.yaml file. We can create this with the following contents:

resolver: lts-11.6 # current resolver

- location: .
- location: ./core # seems like ghc-mod-core got integrated
- location: ../cabal-helper
  extra-dep: true

- extra-1.6.6 # escapeJSON was missing with 1.5.3
- monad-journal-0.7.2
- optparse-applicative-
- unix-compat-
- either-

flags: {}

extra-package-dbs: []

allow-newer: true # so it builds / too lazy to pinpoint exact versions

As you can see we are allowing newer dependencies (so cabal 2 is allowed and will pass through the build process).

Step 4:

With the correct sources and the correct stack.yaml file (attention, it's not .yml, it is really .yaml) we can build ghc-mod executables:

stack install

At the end of this command you should see a message telling that the following executables were installed successfully:

- ghc-mod
- ghc-modi

Step 5:

With the executables created, we can now add those executables to our bin path

sudo cp /home/{{you username}}/.local/bin/ghc-mod /usr/local/bin/
sudo cp /home/{{you username}}/.local/bin/ghc-modi /usr/local/bin/

(Alternatively you can just add the ghc-mod executables to your bin path).

Step 6:

Check your installation:

ghc-mod --version

If everything was build an copied correctly you should see a message similar to this:

ghc-mod version compiled by GHC 8.2.2

I hope this blog post saved you a couple of minutes during the installation of ghc-mod. If you have any questions or comments please use the area below.