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_HOMEon the terminal that is working. This should give something likeM2_HOME=/usr/local/apache-maven/apache-maven-3.1.1 - typing
env | grep JAVA_HOMEshould 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_profilefile and you are good to go now. - open a new terminal and type
mvnthat should work.