84

After upgrading my Mac OSX 10.8 to 10.9, Maven not found in the /usr/share path but its installed in 10.8.

when I try this command:

$ maven -version

got this result

-bash: mvn: command not found

but it worked fine on 10.8? Any idea?

Sahil Mahajan
  • 3,922
  • 2
  • 29
  • 43

8 Answers8

77

Maven is not installed any more by default on Mac OS X 10.9. You need to install it yourself, for example using Homebrew.

The command to install Maven using Homebrew is brew install maven

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • 3
    Yes.. I searched it on google and found a wothy tutorial http://freddy.cellcore.org/post/64860247445/osx-10-9-mavericks-bash-mvn-command-not-found.. Anyways Thanx for your help.. enjoy coding :) – Sahil Mahajan Oct 30 '13 at 10:17
  • 2
    Great answer thanks ,just two things were missing for me (found them on the web) the command you need to run from brew is: brew install maven to install brew run: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" – Asaf Manassen Nov 19 '14 at 09:53
73

if you don't want to install homebrew (or any other package manager) just for installing maven, you can grab the binary from their site:

http://maven.apache.org/download.cgi

extract the content to a folder (e.g. /Applications/apache-maven-3.1.1) with

$ tar -xvf apache-maven-3.1.1-bin.tar.gz

and finally adjust your ~/.bash_profile with any texteditor you like to include

export M2_HOME=/Applications/apache-maven-3.1.1
export PATH=$PATH:$M2_HOME/bin

restart the terminal and test it with

$ mvn -version

Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 17:22:22+0200)
Maven home: /Applications/apache-maven-3.1.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: de_DE, platform encoding: MacRoman
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Philipp Kyeck
  • 18,402
  • 15
  • 86
  • 123
  • you could try and output the PATH `echo $PATH` - is the maven folder included? – Philipp Kyeck Jan 14 '14 at 20:48
  • 2
    I had to use `sudo` before I was able to run maven cleanly from the /Applications/.. folder. I found a combination of http://nofluffjuststuff.com/blog/demian_neidetcher/2013/01/maven_3_maven_2_mixup_on_mac and http://www.journaldev.com/2348/how-to-install-maven-on-mac-os-x-mavericks-10-9 helped me to get unstuck. – JulianHarty Feb 24 '14 at 16:12
  • I had to add entire M2_HOME directory for e.g. export M2_HOME=/Users/km/Applications/apache-maven-3.3.9. Also make sure you quit and restart your terminal. – user358591 Dec 02 '16 at 19:57
59
brew install maven

Please ensure that you've installed the latest Xcode and Command Line tools.

xcode-select --install
Benxamin
  • 4,774
  • 3
  • 31
  • 30
  • Tried this. Now have "Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher" :( – Graham Lea Feb 15 '14 at 11:24
  • 1
    Found somewhere else on the web suggesting the problem was that M2_HOME was set. I can't for the life of me find where it's being set, but putting `unset M2_HOME` into .bashrc made it work. – Graham Lea Feb 15 '14 at 11:39
  • 1
    Cool, the 'xcode-select --install' helped me solve the fact that nothing i had installed via homebrew (mongo, redis, etc) was in my PATH after upgrading to Mavericks – Vasil Daskalopoulos Mar 05 '14 at 03:15
  • This is pretty much the only future-proof solution on here, it always gives the most updated version. – Steven McConnon Jan 16 '15 at 22:03
18
  1. Download Maven from here.
  2. Extract the tar.gz you just downloaded to the location you want (ex:/Users/admin/Maven).
  3. Open the Terminal.
  4. Type " cd " to go to your home folder.
  5. Type "touch .bash_profile".
  6. Type "open -e .bash_profile" to open .bash_profile in TextEdit.
  7. Type the following in the TextEditor

alias mvn='/[Your file location]/apache-maven-x.x.x/bin/mvn'
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdkx.x.x_xx.jdk/Contents/Home/

(Make sure there are no speech marks or apostrophe's) 8. Make sure you fill the required data (ex your file location and version number).

  1. Save your changes
  2. Type ". .bash_profile" to reload .bash_profile and update any functions you add. (*make sure you separate the dots with a single space).
  3. Type mvn -version

If successful you should see the following:

Apache Maven 3.1.1
Maven home: /Users/admin/Maven/apache-maven-3.1.1
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"

Community
  • 1
  • 1
Mo_
  • 181
  • 1
  • 4
11

This solution could seem very long, but it's not. I just included many examples so that everything was clear. It worked for me in Mavericks OS.

Note: I combined and edited some of the answers shown above, added some examples and format and posted the result, so the credit goes mostly to the creators of the original posts.

  1. Download Maven from here.

  2. Open the Terminal.

  3. Extract the file you just downloaded to the location you want, either manually or by typing the following lines in the Terminal (fill the required data):

    mv [Your file name] [Destination location]/ tar -xvf [Your file name]

    For example, if our file is named "apache-maven-3.2.1-bin.tar" (Maven version 3.2.1) and we want to locate it in the "/Applications" directory, then we should type the following lines in Terminal:

    mv apache-maven-3.2.1-bin.tar /Applications/
    tar -xvf apache-maven-3.2.1-bin.tar
    
  4. If you don't have any JDK (Java Development Kit) installed on your computer, install one.

  5. Type "java -version" in Terminal. You should see something like this:

    java version "1.8.0"
    Java(TM) SE Runtime Environment (build 1.8.0-b132)
    Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
    

    Remember your java version (in the example, 1.8.0).

  6. Type "cd ~/" to go to your home folder.

  7. Type "touch .bash_profile".

  8. Type "open -e .bash_profile" to open .bash_profile in TextEdit.

  9. Type the following in TextEdit (copy everything and replace the required data):

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk[Your Java version].jdk/Contents/Home export M2_HOME=[Your file location]/apache-maven-[Your Maven version]/ export PATH=$PATH:$M2_HOME/bin alias mvn='$M2_HOME/bin/mvn'

    For example, in our case we would replace "[Your Java version]" with "1.8.0" (value got in step 5), "[Your file location]" with "/Applications" (value used as "Destination Location" in step 3) and "[Your Maven version]" with "3.2.1" (Maven version observed in step 3), resulting in the following code:

    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
    export M2_HOME=/Applications/apache-maven-3.2.1/
    export PATH=$PATH:$M2_HOME/bin
    alias mvn='$M2_HOME/bin/mvn'
    
  10. Save your changes

  11. Type "source .bash_profile" to reload .bash_profile and update any functions you add.

  12. Type mvn -version. If successful you should see the following:

    Apache Maven [Your Maven version] ([Some weird stuff. Don't worry about this]) Maven home: [Your file location]/apache-maven-[Your Maven version] Java version: [You Java version], vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk[Your Java version].jdk/Contents/Home/jre [Some other stuff which may vary depending on the configuration and the OS of the computer]

    In our example, the result would be the following:

    Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
    Maven home: /Applications/apache-maven-3.2.1
    Java version: 1.8.0, vendor: Oracle Corporation
    Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0</b>.jdk/Contents/Home/jre
    Default locale: es_ES, platform encoding: UTF-8
    OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"
    
GDS
  • 111
  • 1
  • 3
1

For me trying above techniques did work so I opened .bash_profile file and added following line in new line to connect to maven using short cmd :

alias mvn=/opt/apache-maven-3.6.3/bin/mvn

Restart your terminal and hit mvn clean install cmd

Abhishek
  • 1,558
  • 16
  • 28
0

I am not allowed to comment to pkyeck's response which did not work for a few people including me, so I am adding a separate comment in continuation to his response:

Basically try to add the variable which he has mentioned in the .profile file if the .bash_profile did not work. It is located in your home directory and then restart the terminal. that got it working for me.

The obvious blocker would be that you do not have an access to edit the .profile file, for which use the "touch" to check the access and the "sudo" command to get the access

  1. touch .profile

  2. vi .profile

Here are the variable pkyeck suggests that we added as a solution which worked with editing .profile for me:

  1. export M2_HOME=/apache-maven-3.3.3

  2. export PATH=$PATH:$M2_HOME/bin

prakash krishnan
  • 801
  • 6
  • 10
0

For me I had a AdoptOpenJDK 8 installed, instead of SE JDK 8. For which it was not able to recognize JAVA_HOME or mvn commands.

Check your java_home /usr/libexec/java_home -V and use JAVA SE SDK if it is different.

Then follow the above steps to install maven and check again

sachin
  • 481
  • 1
  • 6
  • 7