36

I set the following system veriables (OS = Vista):

M2_HOME = C:\Program Files\Maven 
M2 = %M2_HOME%\bin 
path = %M2% 

If i run mvn -- version I get:

mvn: command not found

Anyone have any idea why this could be? Thanks.

Roaz
  • 363
  • 1
  • 4
  • 6
  • 1
    You can check this answer to the same question. http://stackoverflow.com/questions/3402214/windows-7-maven-2-install – Daniel Albert May 18 '12 at 09:14
  • Do you have the problem described [here](http://www.vistax64.com/vista-account-administration/7649-setting-environment-variables.html) related to permissions and rights? – Raghuram May 18 '12 at 10:14
  • If you make any changes to your system variables, make sure you close and open a new instance of your cmd line. –  Jul 25 '14 at 18:40

9 Answers9

21

Maven setup:

a. install maven from https://maven.apache.org/download.cgi

b. unzip maven and keep in C drive.

c. Set MAVEN_HOME in system variable. enter image description here

d. Set path for maven enter image description here

Abdur Rahman
  • 1,420
  • 1
  • 21
  • 32
11

I followed this tutorial: How to install Maven on Windows

But running mvn -version, I still got:

mvn: command not found

So, I closed the current git window, and opened a new one. Everything went okay :)

valiano
  • 16,433
  • 7
  • 64
  • 79
emdhie
  • 379
  • 1
  • 3
  • 10
  • 2
    git window does not hot-reload the environment variable : so if you modify PATH, you have to close and reopen the git bash. – Poutrathor Jan 14 '19 at 10:46
7

If you are on windows, what i suppose you need to do set the PATH like this:

SET PATH=%M2%

furthermore i assume you need to set your path to something like C:...\apache-maven-3.0.3\ cause this is the default folder for the windows archive. On the other i assume you need to add the path of maven to your and not set it to only maven so you setting should look like this:

SET PATH=%PATH%;%M2%
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I added %M2_HOME% to my current path yes. And I extracted maven into c:\program files\maven. Is it possible that he doesn't know M2_HOME ? Although it shows up in the list of System Variables. – Roaz May 18 '12 at 09:32
  • Sorry i was using M2_HOME instead of M2 – khmarbaise May 18 '12 at 12:15
  • I have made the answer based on your expressions which uses M2 and M2_HOME. You could short cut that by putting C:\..\Maven\bin into your PATH directly. – khmarbaise May 18 '12 at 12:16
  • First expression seems wrong as it would replace the path by %M2%. Would also recommend to update the answer based on the comments as misleading if not reading the comments – goul Aug 01 '17 at 23:55
5

I tried solutions from other threads. Adding M2 and M2_HOME at System variables, and even at User variables. Running cmd as admin. None of the methods worked.

But today I added entire path to maven bin to my System variables "PATH" (C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.1.0\bin) besides other paths, and so far it's working good. Hopefully it'll stay that way.

Howard Lee
  • 977
  • 1
  • 11
  • 20
1

I think the tutorial passed by @emdhie will help a lot. How install maven

But, i followed and still getting mvn: command not found

I found this solution to know what was wrong in my configuration:

I opened the command line and called this command:

../apache-maven-3.5.3/bin/mvn --version

After that i got the correct JAVA_HOME and saw that my JAVA_HOME was wrong.

Hope this helps.

Thiago Bomfim
  • 408
  • 6
  • 12
0
  1. Run 'path' in command prompt and ensure that the maven installation directory is listed.
  2. Ensure the maven is installed in 'C:\Program Files\Maven'.
Maniganda Prakash
  • 4,702
  • 8
  • 34
  • 42
0

I think the problem is with the spaces. I had my variable at the System variables but it didn't work. When I changed variable Progra~1 = 'Program Files' everything works fine.

M2_HOME C:\Progra~1\Maven\apache-maven-3.1.1

I also moved my M2_HOME at the end of the PATH(%M2_HOME%\bin) I'm not sure if this has any difference.

Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
noni_methadoni
  • 132
  • 1
  • 10
0

Follow these steps MAVEN

Again this does not work, hit this command in the Powershell

$env:Path = "$env:Path;C:\path\to\maven\bin"

Make sure to close and reopen the powershell and try mvn -version

Aamer
  • 417
  • 3
  • 9
-1

mvn -version

export PATH=$PATH:/opt/apache-maven-3.6.0/bin