Can't run Apache Maven via command line on El Capitan I have installed Apache Maven 3.3.9 and tried to run it with command line using mvn. 
For this purpose, I added the following symlink but it doesn't work :

sudo ln -s /opt/local/share/java/maven3/bin/mvn /usr/local/bin


I tried first :

sudo ln -s /opt/local/share/java/maven3 /usr/local/bin


But Man mvn and mvn -v don't return anything except errors.
Any idea what I should do ? 
I'm using last version of El Capitan. 
Thanks.

EDIT :

ls -l /usr/local/bin/mvn returns lrwxr-xr-x  1 root  admin  35  2 aoû 21:34 /usr/local/bin/mvn -&gt; opt/local/share/java/maven3/bin/mvn


My PATH contains a bunch of stuff:

/Users/sbdy/anaconda3/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/local/bin:/usr/bin/java:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/usr/X11/bin: No such file or directory
I assume your JAVA_HOME is not configured properly. This will result in an info and error output entering mvn -h or mvn -v.

To install Java 8 and Maven properly do the following:


Download and install the latest JDK 
Open Terminal and enter /usr/libexec/java_home. The result should be (as of August 2016):

/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home

Download and unzip Maven. Move the resulting folder to an appropriate folder (e.g. /opt/)
In Terminal enter nano .bash_profile. Add the lines

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/opt/apache-maven-3.3.9/bin:/...other_paths_already_in_your_profile..:$PATH


save the file to disk and quit nano with ctrlO and ctrlX
Source your modified profile with source .bash_profile or better restart Terminal.


If you have installed maven and/or java with MacPorts or homebrew, the approach is similar the paths to Java/Maven may differ though.