Maven Local Repository is a feature provided in Maven that allows you to manage local copies of your project’s dependencies. By default, Maven makes a copy of each dependency artifact that is used in your project and stores it in the local repository.
- macOS –
/Users/{username}/.m2/repository
- Linux –
/home/{username}/.m2/repository
- Windows –
c:\Users\{username}\.m2\repository
Customize Maven Local Repository
The settings.xml is the main configuration file of Maven. It is available for user-level or system-level configurations.
- Global level: Is available at
${MAVEN_HOME}/conf/settings.xml
is applied for all Maven users on the system that share the same installation. - User level: Can be found at
${HOME}/.m2/settings.xml
. This is the user-specific configuration and overrides the global configuration.
To customize the local repository, edit settings.xml and change directory location with <localRepository> tag.
1 2 3 4 5 | <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> <localRepository>/opt/maven_local_repo</localRepository> |
The configuration file looks like the below:

Define Maven Local Repository at Command Line
Changes made in settings.xml applied for all commands. We can also specify the local repository as a command line parameter using the maven.repo.local
option. which allows us to pass the local repository location as a command-line parameter:
mvn -Dmaven.repo.local=/opt/maven_local_repository install
Conclusion
In this tutorial, you have learned about setting the local repository path in Maven. This local repository is used to store project artifacts.