Stack disk space management

Hi ! My ~/.stack folder is 49 GB so the time is right to do some (early) spring cleaning.

IIUC ~/.stack/programs contains all the various versions of GHC pulled in for each package snapshot, and that alone accounts for 25 GBs. Is it safe to delete it? Will stack re-download the compiler on a need basis (as I hope)?

Last time someone asked on reddit about this all the answers have been tangential/unrelated such as “buy a bigger disk” or “switch to Nix”, but I hope there is a simple, practical fix for this.

Thanks!

3 Likes

I asked this very question on Stack Overflow! The response I got was that it is safe to remove the files within ~/.stack/programs. (I was a little bit miffed, at first, to have gotten a one-sentence answer, but then mollified when I saw that it was from one of the lead Stack developers.)

Anecdotally, Stack seems capable of redownloading not just the GHC binaries but also packages, build plans, snapshots, etc. if you delete them.

1 Like

I think you might even be able to delete the whole ~/.stack and it will download the stuff you need automatically.

Also note that it might be a good idea to use a specific snapshot across multiple projects so stack will reuse the same ghc and packages it already installed. This will save some space and decrease build time (for dependencies).

3 Likes

Do a complete clean out and reinstall. Remove ~/.stack root and branch. Copy over global/stack.yaml and config.yaml - they will be rebuilt. And then only ever use one stack resolver, till you want to do the next upgrade. Stack still gets bloated but the wipe clean is easy.

Build haskell-language-server with that same resolver, and you can’t stray far.

Take a note of all those pesky ~/.local/bin items and replace the ones you still use.

3 Likes

There’s a tool for it at last: https://hackage.haskell.org/package/stack-clean-old

If you find that CLI a little clunky, exploring ~/.stack with https://dev.yorhel.nl/ncdu is a nice quick way to clean up.

6 Likes

I had been using stack v1.9.3 and stack-2.5.1 concurrently do deal with legacy projects and ended up completely messing up my home .stack causing weird compilation issues.
I removed it and it rebuilt itself on next build. Obviously it took much longer.

Thanks! In fact, it would be awesome if this stack-clean-old became absorbed in stack itself.

3 Likes

Agreed, I’m sure work on that would be welcomed.

1 Like

Suggestions/rfe’s for improving the cli UI are welcome :slight_smile:

@ocramz thanks for opening https://github.com/juhp/stack-clean-old/issues/3