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.
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.
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).
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.
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.