Every build tool keeps a copy of each library it downloads, for every version any project ever asked for. On a machine used for a few years of Rust, Go or JVM work, these folders add up to 10 to 50 GB: the Gradle cache alone is often 5 to 20 GB, the Go module cache and ~/.m2 a few GB each.
All of them are caches: the next build downloads what it needs again. What you pay is time and network on that first build, and offline builds fail until then.
What is safe to delete
| What | Where | Safe? |
|---|---|---|
| Cargo registry | ~/.cargo/registry (CARGO_HOME) |
Yes, crates are downloaded again |
| Cargo git checkouts | ~/.cargo/git |
Yes, git dependencies are fetched again |
| Cargo installed tools | ~/.cargo/bin |
No, these are your cargo install commands |
| Go module cache | ~/go/pkg/mod (go env GOMODCACHE) |
Yes, with go clean -modcache |
| Go build cache | Mac ~/Library/Caches/go-build, Ubuntu ~/.cache/go-build (go env GOCACHE) |
Yes, with go clean -cache |
| Maven repository | ~/.m2/repository |
Yes, except artifacts you built with mvn install |
| Maven settings | ~/.m2/settings.xml |
No, it holds mirrors and credentials |
| Gradle caches | ~/.gradle/caches (GRADLE_USER_HOME) |
Yes, with Gradle stopped |
| Gradle wrapper versions | ~/.gradle/wrapper/dists |
Yes, the wrapper downloads its version again |
| Coursier cache | Mac ~/Library/Caches/Coursier, Ubuntu ~/.cache/coursier |
Yes, but JVMs installed with cs live there too |
| Ivy cache | ~/.ivy2/cache |
Yes; keep ~/.ivy2/local (published locally) |
| sbt launcher | ~/.sbt/boot |
Yes, sbt downloads it again |
See the size of each first:
du -sh ~/.cargo/registry ~/.cargo/git ~/go/pkg/mod ~/.m2/repository ~/.gradle/caches ~/.gradle/wrapper/dists ~/.ivy2/cache ~/.sbt/boot 2>/dev/null
du -sh "$(go env GOCACHE)" 2>/dev/null
Rust: Cargo
Cargo 1.88 and newer delete downloaded crates nobody used for three months on their own, so the registry grows more slowly than it used to. To clear it now, stop any running build and remove the downloaded parts:
rm -r ~/.cargo/registry/cache ~/.cargo/registry/src ~/.cargo/git/checkouts
registry/cache holds the .crate files, registry/src their unpacked sources. Never delete ~/.cargo/bin or ~/.cargo/config.toml. The cargo cache command you may see suggested comes from a third-party crate (cargo install cargo-cache), not from Cargo itself.
Each project’s target folder is usually bigger than the registry; see old node_modules and build folders. Old Rust toolchains in ~/.rustup are covered in old runtime versions.
Go
go env GOMODCACHE GOCACHE # where they are
go clean -modcache # downloaded modules
go clean -cache # compiled build results
Use go clean -modcache rather than rm: Go makes module files read-only, so a plain rm -r fails on them. Go already trims build cache entries it has not used for a while, so the module cache is usually the bigger one.
Java: Maven
To clear the whole local repository:
rm -r ~/.m2/repository
To purge only the dependencies of one project, from that project’s folder:
mvn dependency:purge-local-repository
By default this downloads the dependencies again right after; add -DreResolve=false to only remove them. Before wiping the whole repository, check whether you use artifacts you put there with mvn install from another project: they cannot be downloaded, only built again.
Java and Android: Gradle
Gradle removes cache entries unused for 30 days (downloaded files) or 7 days (built ones) on its own, but versions you still build with stay. To clear everything:
./gradlew --stop # or: gradle --stop
rm -r ~/.gradle/caches
rm -r ~/.gradle/wrapper/dists # Gradle versions the wrapper downloaded
Stop the daemons first: a running daemon holds files open and writes back to the cache. Keep ~/.gradle/gradle.properties and ~/.gradle/init.d, which hold your settings. For the Android SDK, emulators and Android Studio’s own folders, see Android Studio disk space.
Scala: Coursier, Ivy and sbt
rm -r ~/.ivy2/cache ~/.sbt/boot
The Coursier cache (~/Library/Caches/Coursier on a Mac, ~/.cache/coursier on Ubuntu, or COURSIER_CACHE) is safe too, but JVMs installed with cs java are stored there; they are downloaded again on next use. Never delete ~/.ivy2/local: it holds what you published with sbt publishLocal.
How CleanMate does it
CleanMate lists these caches in Smart Scan under developer junk, each with its size, on a Mac (all macOS features) and on Ubuntu (all Ubuntu features). Nothing is removed until you confirm.
On a Mac (CleanMate 1.12):
- Cargo registry cache (ticked):
~/.cargo/registryand~/.cargo/git, or underCARGO_HOME; skipped whilecargoruns.~/.cargo/binis never touched. - Go build cache and Go module cache (ticked): found with
go env, cleaned withgo clean -cacheandgo clean -modcache. - Gradle caches (ticked) and Gradle wrapper (unticked), skipped while a Gradle or Kotlin daemon runs.
- Maven repository (unticked), because it may hold artifacts you installed with
mvn install.
On Ubuntu (CleanMate 2.7.0): Go build cache (ticked), Cargo registry cache (registry/cache and registry/src), Gradle caches and Maven repository, these three unticked. The Go module cache and Gradle wrapper versions are not listed on Ubuntu; use the commands above.
On Ubuntu 2.2.0 and from macOS 1.6: the Coursier cache (unticked), Ivy cache and sbt launcher cache, each skipped while sbt, Coursier, Bloop or Metals runs. ~/.ivy2/local is never touched.
Old Rust, Go and Java versions are a separate item, described in old runtime versions; build folders such as target and Gradle’s build in old node_modules and build folders.
The npm, Yarn, pnpm and Bun caches have their own guide: clear the npm, Yarn, pnpm and Bun cache.
FAQ
Will my project still build after clearing these? Yes, with a network connection: the next build downloads what it needs. Offline builds fail until then.
Is go clean -modcache safe? Yes. It removes downloaded modules only, never your code or the installed Go.
Why is ~/.gradle still big after deleting caches? Check ~/.gradle/wrapper/dists (one folder per Gradle version) and ~/.gradle/daemon (logs).
Can I move these caches to another disk? Yes: set CARGO_HOME, GOMODCACHE, GRADLE_USER_HOME or Maven’s localRepository in settings.xml.

