Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not create local repository at /var/root/.m2/repository

Tags:

java

maven

My local maven repo is here /Users/power/.m2/repository.

But I got this error

[java] [ERROR] Could not create local repository at /var/root/.m2/repository -> [Help 1]

Seems Maven thinks that it should use a root user repo. How can I fix it? I don't need to run my maven tasks using root permissions.

like image 345
JohnWinter Avatar asked Jun 15 '15 14:06

JohnWinter


People also ask

Why is m2 unable to find the default Maven local repository?

1.1 If the default .m2is unable to find, maybe someone changed the default path. Issue the following command to find out where is the Maven local repository: mvn help:evaluate -Dexpression=settings.localRepository

Where is the default local repository located?

Usually, this directory is named .m2. Here's where the default local repository is located based on OS: Windows: C:\Users\<User_Name>\.m2 Linux: /home/<User_Name>/.m2 Mac: /Users/<user_name>/.m2. And of course, for Linux and Mac, we can write in the short form: ~/.m2 3. Custom Local Repository in settings.xml

Where are Maven repositories stored?

Local – Folder location on the local Dev machine Central – Repository provided by Maven community Let's now focus on the local repository. 2. The Local Repository The local repository of Maven is a directory on the local machine, where all the project artifacts are stored.

How do I change the local repository path in each IDE?

Each IDE has a separate process to change the local repository path and that you can read its official documentation. For example in Eclipse and STS ( Spring Tools Suite ), we can change the local repository path in the following location: Windows -> Pfreferences -> Maven -> User Settings


3 Answers

Deleting the .m2 folder manually helps sometimes

Your .m2 folder might be corrupted and it doesn't permit you to create new or replace existing with new .m2 folder, so delete the existing .m2 folder manually by entering the below commands.

To view the existing .m2 folder

ls -ltra

To Delete it manually

sudo rm .m2
like image 195
Faizalsrahman Avatar answered Sep 16 '22 22:09

Faizalsrahman


The default maven repository is

${user.home}/.m2/repository/

but you can use settings.xml ( ${user.home}/.m2/settings.xml ) to change it to a folder that you have permissions on. Or conf/settings.xml in the ${MAVEN_HOME} and change:

<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>

Ideally, you should run maven as yourself and not root to make sure you have permissions or doing 'ksu' first and then use command line.

like image 38
ingrid.e Avatar answered Sep 17 '22 22:09

ingrid.e


This error can occur if there is a file called .m2. (Most probably created mistakenly. This happened to me when I copied settings.xml as .m2) If you can delete this and run mvn command again it will create the .m2 folder and you can proceed without a hassel.

like image 27
Adiesha Avatar answered Sep 16 '22 22:09

Adiesha