A couple ideas... First, just to reformat for readability, this is your PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
These are your env vars:
export JAVA_HOME=/usr/local/jdk1.6.25/
export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
Note that "java" (the program) is in $JAVA_HOME/bin
, not $JAVA_HOME
. That will cause a little confusion when a different 'java' is found in the shell's PATH. For example...
$ type java
java is /usr/bin/java
So just modify your PATH:
$ export PATH=$JAVA_HOME/bin:$PATH
$ type java
... should be $JAVA_HOME/bin/java ...
But I don't think that's the issue. From the mvn shell script launcher,
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
This would imply the var really isn't set -- not merely set to a wrong value. Perhaps this is the key hint:
[my java_home ...] even though it exists in my environment file?
Perhaps you added/modified JAVA_HOME
to .bashrc
or .profile
, and then in the same shell tried to run mvn -v
?? If so, these values won't be picked up until you source the file (e.g., . ~/.bashrc
) or create a new login shell (bash -l
) in order for these env var's to be set (or reset).
(Also... it's just a matter of opinion, but in your PATH
, I'd leave the standard /usr/bin
(and /usr/sbin
and /bin
) in front of any /usr/local/bin
or /opt/bin
(etc), just to avoid any rouge 'local' programs taking precedence over the standard programs... using something like alternatives
would be preferable to override the default versions of standard applications.)
Add those export
lines to your ~/.profile
file.
If you want it to apply to all users on the system, put it in /etc/profile
instead;
sudoedit /etc/profile
Once you've edited either, you'll see the effect next time you log in.
See also http://mywiki.wooledge.org/DotFiles
On a side-note, if you instead install maven via the software center or apt-get
, you won't need to do any of the above.
Best Answer
Okay finally what I did was the same I did for installing java jdk environment i.e adding maven variables in
/etc/profile
. The steps are described below:-Add these commands at the end of the text file
export M2_HOME=/opt/apache-maven-3.3.9
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
Reload
profile
by typingsource /etc/profile
in command lineRestart the system
Verify
M2
by typingecho $M2
in command linePATH
by typingecho $PATH
in command line. Check if there is maven directory in thePATH
variable or not.maven version
by typingmvn -version
in command line