# Why is HLS asking ghcup to install GHC?

**URL:** <https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734>\
**Category:** Learn\
**Created:** [February 5, 2024, 3:52pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734 "2024-02-05T15:52:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 3:52pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/1 "2024-02-05T15:52:04Z")

</div>

Occasionally when I’m using HLS (via emacs’s `lsp` mode) I see that in the background `ghcup` is installing some version of GHC that I don’t have. Often I don’t have enough free space, so it just dies. I’ve ended up with `.ghcup/tmp` containing 8 GB of temporary files from aborted installs!

I don’t understand why HLS is asking `ghcup` to install anything. `lsp` mode and HLS are working fine, so it doesn’t seem like I _need_ a new version of GHC installed.

Why is it happening, and is there a way I can disable this behaviour?

(I’m currently using HLS `2.5.0.0` but it also happened with whichever version of HLS I was using before, too.)

---

<div class="post-metadata">

**Author:** ![michaelpj](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/michaelpj/32/417_2.png) [@michaelpj](https://discourse.haskell.org/u/michaelpj)\
**Post date:** [February 5, 2024, 4:16pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/2 "2024-02-05T16:16:00Z")

</div>

That seems extremely weird. HLS does not call ghcup, it does call your build tool to get flag information but that’s about it.

The vscode extension does call ghcup to install HLS, but not GHC. Not that that’s relevant since you’re using Emacs.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 4:23pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/3 "2024-02-05T16:23:16Z")

</div>

Oh, OK, thanks, how mysterious. Next time it happens I’ll do a `pstree` to try to determine exactly what process is causing `ghcup` to be run. It must be _something_ to do with HLS because I only ever see this when using HLS (through `lsp`). That doesn’t mean it’s HLS that is responsible, of course. It could be something else in my `emacs` config that’s doing it …

---

<div class="post-metadata">

**Author:** ![michaelpj](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/michaelpj/32/417_2.png) [@michaelpj](https://discourse.haskell.org/u/michaelpj)\
**Post date:** [February 5, 2024, 4:27pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/4 "2024-02-05T16:27:19Z")

</div>

Is it a stack project where you installed stack with ghcup? It looks like then stack will call ghcup sometimes. I think HLS calls something like `stack setup`, so conceivably in that situation it could trigger downloading GHC?

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 4:36pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/5 "2024-02-05T16:36:32Z")

</div>

I have one stack-using project open, which is `stan`, and indeed I have `stack` installed via `ghcup` (although I don’t use `stack` myself). I don’t see anything in the [current `stan`](https://github.com/kowainik/stan/tree/a610d74fcb4a852a9e6b0926580c055bb3dddc23) that would request `ghc-9.4.7`, which is what `ghcup` was trying to download, but perhaps this is indeed the problem. I’ll keep an eye on it.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 4:38pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/6 "2024-02-05T16:38:52Z")

</div>

Although if I do `stack build` in the `stan` directory it does try to download `ghc-9.6.4`, so maybe this is the root cause. I was pretty sure HLS was using `cabal` on this project though … It looks like I don’t have a `hie.yaml` here, so I am not certain …

---

<div class="post-metadata">

**Author:** ![michaelpj](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/michaelpj/32/417_2.png) [@michaelpj](https://discourse.haskell.org/u/michaelpj)\
**Post date:** [February 5, 2024, 4:44pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/7 "2024-02-05T16:44:59Z")

</div>

If there is both cabal and stack configuration in a project and no `hie.yaml`, then we guess stack. Sounds like that’s the culprit.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 4:51pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/8 "2024-02-05T16:51:35Z")

</div>

That sounds pretty plausible but I don’t really understand what I’m seeing, because in the logs I see this from 10 minutes ago when I just tried (and posted my message):

```nohighlight
2024-02-05T16:42:35.349366Z | Debug | executing command: cabal --builddir=/home/tom/.cache/hie-bios/dist-stan-624f6e53d42a862e637781e3061ca192 v2-repl --with-compiler /home/tom/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/tom/.cache/hie-bios/ghc-pkg-6ab590ecd05b25ce2522f0302b32bac5 lib:stan

```

I don’t see any evidence it has tried to use `stack` for anything and I definitely don’t have a `hie.yaml`.

---

<div class="post-metadata">

**Author:** ![michaelpj](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/michaelpj/32/417_2.png) [@michaelpj](https://discourse.haskell.org/u/michaelpj)\
**Post date:** [February 5, 2024, 4:54pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/9 "2024-02-05T16:54:58Z")

</div>

The other variable is that `stack` needs to be on the path, if that could have changed.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 4:57pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/10 "2024-02-05T16:57:50Z")

</div>

Doesn’t look like it. Seems like it’s been there since October:

```nohighlight
% ls -l $(which stack)
lrwxrwxrwx 1 tom tom 12 Oct 29 15:02 /home/tom/.ghcup/bin/stack -> stack-2.11.1

```

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 5, 2024, 7:32pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/11 "2024-02-05T19:32:18Z")

</div>

OK, I think I’ve seen enough to understand most of what’s going on now. Here’s `pstree` during the latest occurrence:

```nohighlight
           |-screen(1428354)---emacs(1428356)-+-aspell(1526625)
           | |-haskell-languag(1913455)-+-{haskell-languag}(1913785)
           | | |-{haskell-languag}(1913786)
...
           | |-stack(1965609)-+-sh(1965614)---ghcup(1965616)-+-{ghcup}(1965624)
           | | | |-{ghcup}(1965625)
...
           | | |-{stack}(1965610)
...
           | |-{emacs}(1428408)
...

```

So `ghcup` is being called by `stack` which itself is being called by `emacs`.I would have expected to see it called by `haskell-language-server`, but maybe there’s some parent misattribution there. `ghcup` is trying to install `ghc-9.4.7`

```nohighlight
% ps aux | grep '[^.]ghcu[p]'
tom 1965616 32.3 0.2 1073760360 23280 ? Sl 19:17 0:15 ghcup run --ghc 9.4.7 --install

```

`emacs`'s `*Messages*` gives a clue why `9.4.7` specifically:

```nohighlight
         /home/tom/.ghcup/ghc/9.4.7/bin/ghc: getFileStatus: does not exist (No such file or directory)
Error: [S-6362]
No compiler found, expected minor version match with ghc-9.4.7 (x86_64-tinfo6-libc6-pre232) (based on resolver setting in /home/tom/.stack/global-project/stack.yaml).
To install the correct GHC into /home/tom/.stack/programs/x86_64-linux/, try running 'stack setup' or use the '--install-ghc' flag. To use your system GHC installation, run 'stack config set system-ghc --global true', or use the '--system-ghc' flag.

Try installing a more recent version of haskell-stack-ghc, and please open a bug report if the issue persists in the latest release. Thanks!

```

and indeed:

```nohighlight
% cat .stack/global-project/stack.yaml
...
packages: []
resolver: lts-21.18

```

[LTS 21.18](https://www.stackage.org/lts-21.18) is `ghc-9.4.7`. I don’t, however, understand why `stack` run through HLS is using `stack/global-project/stack.yaml` when there’s a `stack.yaml` in `stan`'s top-level directory.

Anyway, the main mystery is resolved. I guess I should just use `hie.yaml` and ask for `cabal`. Thanks again for your help, @michaelpj.

---

<div class="post-metadata">

**Author:** ![philderbeast](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/philderbeast/32/2489_2.png) [@philderbeast](https://discourse.haskell.org/u/philderbeast)\
**Post date:** [February 5, 2024, 10:19pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/12 "2024-02-05T22:19:34Z")

</div>

Since going all in on ghcup, I’ve configured stack to only use the system ghc and not to install it with:

```nohighlight
$ stack config set system-ghc true --global
$ stack config set install-ghc false --global

```

```nohighlight
$ cat ~/.stack/config.yaml
...
system-ghc: true
install-ghc: false

```

I don’t see stack trying to install GHC anymore with this configuration.

---

<div class="post-metadata">

**Author:** ![mpilgrem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mpilgrem/32/2529_2.png) [@mpilgrem](https://discourse.haskell.org/u/mpilgrem)\
**Post date:** [February 5, 2024, 11:55pm UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/13 "2024-02-05T23:55:44Z")

</div>

Stack will use GHCup to manage versions of GHC if you have (a) customised Stack to do so (possibly by asking GHCup to customise Stack in that way on set up) and (b) not set Stack to try to use the version of GHC on the PATH (`system-ghc: true`) - see [Configuration (project and global) - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-installation-customisation). If you want Stack to manage versions of GHC directly, delete `ghc-install.sh` from the `hooks` directory in the Stack root directory (`stack path --stack-root`).

When GHCup is being used to manage versions of Stack, it puts a small exectuable named `stack` on the PATH that runs the specified version of Stack (also named `stack`). (As an aside, this interferes with Stack’s own management of versions of Stack.)

If you set `system-ghc: true`, Stack will try to use the GHC version on the PATH, if it is the correct version. If you set `install-ghc: false` and Stack is managing versions of GHC directly (not via GHCup), Stack will not try to install the correct version of GHC if it is not available.

EDIT: So, as @philderbeast rightly advises, if somebody is using GHCup to manage manually the version of GHC on the PATH and that user does not want Stack to fetch automatically (via GHCup or otherwise) GHC if the correct version is not available to Stack on the PATH, the user needs to configure Stack with `system-ghc: true` and `install-ghc: false` (either at the level of the individual project in `stack.yaml` or, more likely, globally in `config.yaml`).

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [February 6, 2024, 8:01am UTC](https://discourse.haskell.org/t/why-is-hls-asking-ghcup-to-install-ghc/8734/14 "2024-02-06T08:01:18Z")

</div>

> [@philderbeast](#):
>
> ```haskell
> stack config set install-ghc false --global
> 
> ```

Thanks, I’ll do that!
