SiftMac
Is it safe to delete? · Package caches · Updated 21 November 2026

Is it safe to delete ~/.m2/repository?

By Mohit Nippanikar, who makes SiftMac

The short answer
On this page
  1. What the local repository is
  2. Where it is
  3. How big it gets
  4. How to clear it
  5. What happens afterwards
  6. Build output in projects
  7. Questions

1. What the local repository is

Maven’s docs describe the local repository as a directory on your computer that caches remote downloads and contains temporary build artifacts you haven’t released yet. Every Maven project on your Mac, and IDEs that build them, share it.

2. Where it is

~/.m2/repository
~/.m2/settings.xml
~/.m2/wrapper

~/.m2/repository is the default local repository; a <localRepository> entry in settings.xml can move it. settings.xml holds your user settings, including the repository usernames and passwords Maven says belong there rather than in a pom.xml. ~/.m2/wrapper is where the Maven Wrapper (./mvnw) installs the Maven versions your projects ask for.

3. How big it gets

du -sh ~/.m2/repository ~/.m2/wrapper
du -sh ~/.m2/repository/* | sort -h | tail

The second command shows the largest top-level groups, so you can see which libraries and plugin families take the most.

4. How to clear it

Maven’s docs say you shouldn’t need to do anything with the local repository regularly, except clean it out when you’re short on disk space, or erase it completely if you’re willing to download everything again. Choose how far to go:

mvn dependency:purge-local-repository -DreResolve=false
rm -rf ~/.m2/repository/*

Before emptying it, note which of your own modules you installed locally (look for your own group ID in the folder), so you know which projects need mvn install again. Keep settings.xml.

5. What happens afterwards

6. Build output in projects

Each Maven project also keeps its build output in its own folder, usually target. mvn clean runs the Clean Plugin, which deletes the project’s build directories, and the next build makes them again. Gradle projects keep a similar shared cache in [~/.gradle](/safe-to-delete/gradle-caches).

Questions

Will deleting ~/.m2 delete my Maven settings?

Deleting the whole ~/.m2 would: settings.xml lives there, with mirrors, profiles and server credentials. Clear ~/.m2/repository instead and the settings stay.

Why is one of my libraries missing after I cleared the repository?

If it’s one of your own modules, it only ever existed on your Mac, put there by mvn install. Build and install that module again; libraries from a remote repository download by themselves.

Can I delete only old versions?

Yes. Version folders a project no longer uses can go one at a time, at ~/.m2/repository/<group path>/<artifact>/<version>; if a build still needs one, Maven downloads it again.

Does mvn clean empty ~/.m2?

No. mvn clean only deletes one project’s build output. The local repository is shared by all your projects and has no clean command of its own.

How SiftMac handles it. SiftMac doesn’t clear ~/.m2. Its space map shows the repository’s size and notes that its libraries download again on the next build. It also doesn’t list Maven projects’ target folders: its target rule is for Rust projects with a Cargo.toml.

Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works