Skip to content

Haskell keeps a compiler per resolver and a package database per project

GHC installs, package databases and dist folders accumulate quickly. Where they are and which commands prune them.

4 min read

Haskell tooling is thorough about reproducibility, which means it installs a compiler per resolver and builds its own copy of every dependency. Both are the right decisions and both use a great deal of disk.

Where it goes

du -sh ~/.stack ~/.cabal ~/.ghcup 2>/dev/null | sort -h
du -sh ~/.stack/programs/* ~/.ghcup/ghc/* 2>/dev/null | sort -h | tail
find ~ -maxdepth 5 -type d \( -name dist-newstyle -o -name .stack-work \) \
  2>/dev/null -exec du -sh {} + | sort -h | tail -15
LocationWhat it isSafe to remove
~/.stack/programsA GHC per resolver, 2 GB and up eachYes, redownloaded
~/.ghcup/ghcGHC versions installed by ghcupYes, via ghcup
~/.cabal/storeBuilt packages per compiler versionYes, rebuilt
.stack-work in a projectBuild outputYes
dist-newstyle in a projectBuild outputYes

The compilers are the big items

A GHC installation is a couple of gigabytes, and a machine that has followed a few resolvers has several. Removing the ones no project pins is the largest single reclaim:

ghcup list
ghcup rm ghc 9.4.7
stack ls dependencies 2>/dev/null | head

Build output across projects

dist-newstyle and .stack-work are per project and regenerated by the next build, exactly like Rust target folders. For a project you are not building this week, both are free space.

The store is a cache with a caveat

~/.cabal/store holds built packages per compiler version, so clearing it means rebuilding rather than redownloading, which for a large dependency tree is a long compile. Prune the compiler versions you no longer use rather than the store as a whole, and most of the store goes with them.

Common questions

Why does Haskell use so much disk space?

Because Stack installs a GHC per resolver, each a couple of gigabytes, and every project builds its own copy of dependencies into a store and a build directory.

Can I delete .stack-work and dist-newstyle?

Yes. Both are build output regenerated by the next build. For projects you are not currently working on, they are free space at the cost of one rebuild.

How do I remove old GHC versions?

Use ghcup list and ghcup rm ghc followed by the version, or remove unused entries under ~/.stack/programs. Each is a couple of gigabytes and nothing removes them automatically.

Should I clear the cabal store?

Prune compiler versions instead. The store holds built packages per compiler, so clearing it means recompiling rather than redownloading, which is much slower for a large dependency tree.

Read next