mvn command not working on mac OS X Yosemite

21,739

export PATH=$M2:$PATH should be export PATH=$M2/bin:$PATH or export PATH=$M2_HOME/bin:$PATH

Also JAVA_HOME should be something like this

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60

then

export PATH=$JAVA_HOME/bin:$PATH

That's all.

All in one

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH
Share:
21,739
John
Author by

John

Updated on August 04, 2022

Comments

  • John
    John almost 2 years

    I have performed all the necessary steps like the following after referring other Stack overflow threads and online resources for installing / configuring maven. Here is what I did :

    export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
    
    export M2=$M2_HOME/bin
    

    My Java Home variable is also, set, as shown below:

    echo $JAVA_HOME
    
    /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home
    
    export PATH=$M2:$PATH  
    

    Inspite of doing all of the above, when I run mvn --version, I get Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home/bin/java.

    PATH Output is as follows :

     echo $PATH
    /usr/local/apache-maven/apache-maven-3.3.9/bin:/usr/local/apache-maven/apache-maven-3.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/MacGPG2/bin
    
  • javapapo
    javapapo over 8 years
    I would also like to add as a side note that you can make your life a lot easier if you choose to use a package manager that can do most of the manual work for you in terms of installing and placing things in path. If you have some time - have a look on brew and brew cask . See here or here
  • John
    John over 8 years
    @11thdimension Thanks for the answer and comment javapapo. My path variable is echo $PATH /usr/local/apache-maven/apache-maven-3.3.9/bin:/usr/local/ap‌​ache-maven/apache-ma‌​ven-3.2.1/bin:/usr/l‌​ocal/bin:/usr/bin:/b‌​in:/usr/sbin:/sbin:/‌​usr/local/git/bin:/u‌​sr/local/MacGPG2/bin I made the changes in JAVA_HOME variable as suggested. Still, I need to run sudo mvn --version to make sure that maven is running properly. If I just run mvn --version without sudo, I get the error Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.8.0_60/bin/java
  • John
    John over 8 years
    Could anyone explain me why it throws JAVA_HOME error in spite of setting the path correctly?
  • 11thdimension
    11thdimension over 8 years
    Are you able to use Java commad in the terminal ? If you are able to use it, then try to run which java, which will give you the correct path to java executable. Post the output if you can find the path.
  • John
    John over 8 years
    @11thdimension When I ran the following command on the terminal:ls -l which java``, I got the following :` lrwxr-xr-x 1 root wheel 74 Jun 25 2015 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current‌​/Commands/java`
  • 11thdimension
    11thdimension over 8 years
    what is the content of /Library/Java/JavaVirtualMachines/jdk1.8.0_60/Contents/Home directory ?