12

How to prevent stack from downloading GHC for every new project?

Every time I create a new project using stack and then build or exec the codes, stack will install a new GHC for me. This is not only boring for waiting such a long time for a huge image to be downloaded (behind the GFW, xKib/s), but also a space disaster for my pity 128G SSD Macbook Pro. How can I fix this?

$ stack exec blah
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
ghc-8.4.4:   15.98 KiB / 220.05 MiB (  0.01%) downloaded...^C
cmal
  • 2,062
  • 1
  • 18
  • 35

2 Answers2

11

Stack only installs a new ghc if the stack.yaml you are using requires some ghc version that you do not yet have installed via stack. Once stack has installed ghc-8.4.4, for example, it will not reinstall this version of ghc.

I would presume the solution, then, is to make sure you are using the same resolver for all of your projects, so that stack only installs the one ghc version.

Dan Burton
  • 53,238
  • 27
  • 117
  • 198
4

Just find $HOME/.stack.yaml and add:

# Turn on system GHC
system-ghc: true

and run the same command again.

cmal
  • 2,062
  • 1
  • 18
  • 35
  • 3
    Looks like things have changed, this now goes in ~/.stack/config.yaml. You will also need to change `resolver` in your project's `stack.yaml` to be `resolver: ghc-8.8.2` or whatever matches `ghc --version` – Joe the Person Apr 30 '20 at 21:55