mvn command not found in OSX Mavrerick
Try following these if these might help:
Since your installation works on the terminal you installed, all the exports
you did, work on the current bash and its child process
. but is not spawned to new terminals
.
env
variables are lost if the session is closed; using .bash_profile
, you can make it available in all sessions, since when a bash
session starts, it 'runs' its .bashrc and .bash_profile
Now follow these steps and see if it helps:
type
env | grep M2_HOME
on the terminal that is working. This should give something likeM2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
typing
env | grep JAVA_HOME
should give like this:JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Now you have the PATH for M2_HOME
and JAVA_HOME
.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin
, you will see mvn
binary there.
All you have to do now is to point to this location everytime using PATH. since bash
searches in all the directory path mentioned in PATH
, it will find mvn
.
now open
.bash_profile
, if you dont have one just create onevi ~/.bash_profile
Add the following:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
save the file and type
source ~/.bash_profile
. This steps executes the commands in the.bash_profile
file and you are good to go now.open a new terminal and type
mvn
that should work.
Solutions above are good but they require ~/.bash_profile. /usr/local/bin
is already in the $PATH and it can be confirmed by doing echo $PATH
. Download maven and run the following commands -
$ cd ~/Downloads
$ tar xvf apache-maven-3.5.3-bin.tar.gz
$ mv apache-maven-3.5.3 /usr/local/
$ cd /usr/local/bin
$ sudo ln -s ../apache-maven-3.5.3/bin/mvn mvn
$ mvn -version
$ which mvn
Note: The version of apache maven would be the one you will download.
Here is what worked for me.
First of all I checked if M2_HOME variable is set env | grep M2_HOME
. I've got nothing.
I knew I had Maven installed in the folder "/usr/local/apache-maven-3.2.2", so executing the following 3 steps solved the problem for me:
- Set M2_HOME env variable
M2_HOME=/usr/local/apache-maven-3.2.2
- Set M2 env variable
M2=$M2_HOME/bin
- Update the PATH
export PATH=$M2:$PATH
As mentioned above you can save that sequence in the .bash_profile
file if you want it to be executed automatically.