Maven "Could not create local repository" - Fix ~/.m2 Permissions
By Daniel Zoghalchali·Latchkey
Maven could not create the local repository directory it caches artifacts in. The configured path is not writable - wrong ownership in a container, a read-only mount, or a bad <localRepository>.
What this error means
Maven fails at startup with Could not create local repository at /path/.m2/repository before resolving anything. The path is unwritable for the user the job runs as.
mvn output
[ERROR] Could not create local repository at /home/runner/.m2/repository
-> [Help 1]
Common causes
Unwritable or wrong-owner ~/.m2
In a container, the job user may differ from the directory owner, or HOME may be unset, so Maven cannot create ~/.m2/repository.
localRepository points at a read-only path
A <localRepository> in settings.xml (or -Dmaven.repo.local) pointing at a read-only mount or a non-existent parent cannot be created.
How to fix it
Point the local repo at a writable path
Set a job-local, writable repository directory explicitly.
Set -Dmaven.repo.local to a writable, cacheable path in CI.
Ensure HOME and ownership are correct for the job user in containers.
Avoid mounting ~/.m2 read-only when the build must write to it.
Frequently asked questions
What causes ""Could not create local repository""?
In a container, the job user may differ from the directory owner, or HOME may be unset, so Maven cannot create ~/.m2/repository.
How do I fix "Could not create local repository"?
Set a job-local, writable repository directory explicitly.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.