Is it safe to delete the ~/.m2 folder on Mac?
Safe with care~/.m2
Only the repository part. What Maven keeps in ~/.m2, which files hold your passwords, and how to clear the local repository without losing anything.
Verdict: Safe with care. You can delete ~/.m2/repository, Maven's local repository, and Maven downloads what it needs again on the next build. Keep settings.xml and settings-security.xml, which hold your Maven settings and server passwords, and check for libraries you built yourself with mvn install, because those exist nowhere else.
What lives in ~/.m2
~/.m2 is Maven's folder in your home directory. It usually holds three things:
settings.xml: your user settings. The Maven settings reference says Maven merges this file with the global one, with your user file winning, and that itsserverssection holds the username and password for each repository you log in to.settings-security.xml: if you encrypt those passwords, Maven's password encryption guide puts the encrypted master password here. The guide warns to treat it as if the password were stored in plain text.repository: the local repository, which the settings reference gives as the defaultlocalRepository. Maven's introduction to repositories describes it as a folder that "caches remote downloads and contains temporary build artifacts that you have not yet released".
Maven isn't the only user. IntelliJ IDEA's Maven support and Gradle builds that use mavenLocal() read the same repository folder.
What happens if you delete it
repository, downloaded parts: rebuilt automatically. The next build of each project downloads its dependencies again, so it is slow and needs a network connection. Offline builds fail until the cache refills.repository, your own builds: anything you put there withmvn install, such as snapshot versions of your own libraries, is lost for good. That is the "temporary build artifacts that you have not yet released" in Maven's description. Rebuild them from source by runningmvn installin each library project.settings.xmlandsettings-security.xml: lost for good unless backed up. Builds that use private repositories stop authenticating, and mirrors, proxies and profiles you set up stop applying.
How to check its size safely
These commands only read. The first shows the folder and the repository's share of it, and the second lists the biggest top-level groups inside the repository:
du -sh ~/.m2 ~/.m2/repository 2>/dev/null
du -sh ~/.m2/repository/* 2>/dev/null | sort -h | tail -15
Group folders follow Java package names, such as org, com and io, so a big org folder is usually shared libraries rather than one project.
In Finder, choose Go > Go to Folder, type ~/.m2 and press Return. The folder is hidden because its name starts with a dot. Select repository and choose File > Get Info for its size.
On the macOS 15.5 Mac we checked this on, there was no ~/.m2, because Maven had never run there. If you don't build Java projects, you won't have one either.
The safest way to get the space back
You only need to clear repository, so the settings files can stay exactly where they are.
- Quit your IDE and let any running build finish.
- Move the repository to the Bin, so you can put it back if a build breaks:
trash ~/.m2/repository
The trash command comes with macOS 14 Sonoma and later. To clear less, move only one group, such as trash ~/.m2/repository/com/example.
- Run
mvn installin any library project of your own that other projects depend on. - Build a project you work on. When it succeeds, empty the Bin.
Warning: rm -rf ~/.m2 deletes your settings and password files along with the repository, skipping the Bin. Clear repository on its own instead.
What never to touch
settings.xmlandsettings-security.xml. Back them up somewhere private, since they hold credentials.- The repository while a build is running. Half-deleted folders can leave broken downloads behind.
- The repository if you work offline and can't download dependencies again soon.
Gradle keeps a similar cache in ~/.gradle, and Rust in ~/.cargo. For the bigger picture, the guide to freeing up space on a Mac covers everything else worth checking.
How Headroom helps
Headroom doesn't clean ~/.m2. Its free Space map shows how big the folder is next to everything else in your home folder, and Show in Finder takes you straight to it, so you can see whether Maven's repository is worth clearing before you touch it. For developer caches Headroom does clear, such as Gradle's and Cargo's downloads, Clean lists each one with its size. The scan is free, and the $19 one-time licence clears what you tick on up to three Macs. See the disk map or download Headroom.
Questions
Can I delete the ~/.m2/repository folder?
Yes. Maven downloads every dependency again on the next build. Rebuild any of your own libraries that only existed locally with mvn install.
Where is the Maven settings file on a Mac?
Your user settings live in ~/.m2/settings.xml. Maven merges it with the global settings file in its installation, and your user file takes priority.
Will deleting ~/.m2 delete my passwords?
It will if you delete the whole folder. Server usernames and passwords live in settings.xml, and the master password for encrypted ones lives in settings-security.xml, so keep both.
Why is ~/.m2/repository so big?
It keeps every version of every dependency that any project on your Mac has downloaded, plus anything you installed locally, so it grows as your projects update their dependencies.