CleanMate

All guides · macOS and Ubuntu · Updated

Rust, Go and Java package caches filling your disk: Cargo registry, Go module cache, Maven ~/.m2, Gradle, Coursier and Ivy on Mac and Ubuntu

Where Cargo, Go, Maven, Gradle, Coursier, Ivy and sbt keep downloaded packages on a Mac and on Ubuntu, how big they get, how to clear them (go clean -modcache, mvn dependency:purge-local-repository, Gradle caches) and what not to delete.

Download for macOS · Install on Ubuntu — free and open source

CleanMate on a Mac after a Smart Scan cleanup of the Cargo, Go, Gradle and Maven caches, showing the space freedCleanMate on a Mac after a Smart Scan cleanup of the Cargo, Go, Gradle and Maven caches, showing the space freed

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

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.

Skip the commands

CleanMate runs on both systems: pick yours.

Open source — star it on GitHub: CleanMate for macOS · CleanMate for Ubuntu

How CleanMate decides what is safe to remove →