In a ghcup-based setup how to tell stack to use the "recommended" ghc?

I have installed ghcup, then through this the recommended ghc 8.10.7, HLS and now stack 2.7.5.

ghc runs perfectly, but stack always complains: “No compiler found, expected minor version match with ghc-8.6.5 (x86_64) […]” even with --system-ghc or the equivalant config setting.

The problem, I guess, is that stack wants ghc 8.6.5, but I have the “recommended” 8.10.7.

I would like to avoid multiple ghcs on my system (as long as I can avoid it). Also for now I would like to go only with stack, not cabal-install, if possible.

Therefore, I assume, I need to tell stack through its “resolver” setting, to use ghc v8.10.7 – but how do I do this?

Or does it make more sense to downgrade the system compiler to ghc 8.6.5 (what stack expects by default). When staring out with Haskell, should I definitely stick to ghc 8.10.7, or can 8.6.5 be recommended for learning too?

Thanks for suggestions!

1 Like

For stack you can either use the snapshot/resolver settings in your stack.yaml (for example resolver: ghc-8.10.7 or on the command line with something like stack --resolver ghc-8.10.7 new Test) or you can look for the right stackage snapshot for you desired compiler and use this for the resolver setting (in your case the latest LTS seems to be 18.28 - so stack --resolver lts-18.28 new Test)

As to learning I think it does not really matter what GHC version you are using - I think most if not all of the material covered in introductory courses does not target any GHC specific version (or GHC at all).

PS: What do you mean “stack expects by default”? If you initialize a new project (I’d recommend you use a project approach even for learning - it’s much easier to get to packages etc. this way) then stack should look for the latest LTS and use this by default.

If you use something like stack repl from a folder without a project structure (stack.yaml, …) stack should use a default setting file located in your stack-installation folder under [stack-root]/global-project/stack.yaml and you can adjust that to your liking (change the resolver there - it is likely the one current when you installed stack)

you can find the stack-root with stack path (should be printed out at the top of that output)

1 Like

Thanks for your detailed information! :slight_smile:

Well, I just referred to what stack does when used outside a project context.

Well, that’s not really what I want either, because the latest snapshot uses ghc-9.0.2. – I guess I have to set the the resolver in ~/.stack/stack.yaml to lts-18.28 as well.

Your best shot is my PR here:

Build stack from that branch yourself, then add a file ~/.stack/hooks/, make it executable and add these contents:


set -Eeuo pipefail

case "$HOOK_GHC_TYPE" in
		>&2 echo "Installing GHC via ghcup"
		echo "$(ghcup run -i --ghc "$HOOK_GHC_VERSION")"/ghc
		>&2 echo "Hook doesn't support installing from source"
		exit 1
		>&2 echo "Unsupported GHC installation type: $HOOK_GHC_TYPE"
		exit 2

Now stack will use ghcup to install and detect the correct GHC versions automatically. Without --system-ghc (make sure it’s off).

If you don’t want to do that, you can configure stack to use a specific compiler for a project (in stack.yaml):

resolver: lts-18.16
compiler: ghc-8.10.6
compiler-check: match-exact

You probably also want to add this to your global ~/.stack/config.yaml:

system-ghc: true
install-ghc: false