Monday, October 25, 2010

Updating to Maven 3 in Mac OS X Snow Leopard

Mac OS X 10.6.5 ships with Maven 2.2.0 installed. Invoking Maven from the Terminal with the mvn -v command produces the following output:
  bash-3.2# mvn -v
  Apache Maven 2.2.0 (r788681; 2009-06-26 06:04:01-0700)
  Java version: 1.6.0_22
  Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x" version: "10.6.5" arch: "i386" Family: "mac"
To manually upgrade to Maven 3, complete these 3 steps:
  1. Download Maven 3 archive
  2. Unpack archive into /usr/share/java/
  3. Link /usr/share/maven to /usr/share/java/apache-maven-3.0.1
Below are the details of each step.

1. Download Maven 3 archive
Go to the Maven download site and download the file named “apache-maven-3.0.1-bin.tar.gz” to your Desktop.

2. Unpack archive into /usr/share/java/
Open the Terminal. You will need root access to install Maven. Type the following to open a root shell:
  sudo bash
Type your administrator password if prompted. Copy the file that you downloaded in step 1 to the directory where the new Maven will be installed by typing this command:
  cp ~/Desktop/apache-maven-3.0.1-bin.tar.gz /usr/share/java/
Change to the installation directory by entering this command:
  cd /usr/share/java/
Unpack the archive, which will create a new directory called apache-maven-3.0.1:
  tar xzf apache-maven-3.0.1-bin.tar.gz
Remove the archive file - it is no longer needed:
  rm apache-maven-3.0.1-bin.tar.gz
Remove quarantine status from trusted Maven installation files:
  xattr -dr apache-maven-3.0.1/
Reduce the permissions on config and JAR files with these commands:
  chmod 755 /usr/share/java/apache-maven-3.0.1/conf
  chmod 644 /usr/share/java/apache-maven-3.0.1/conf/settings.xml
  chmod 644 /usr/share/java/apache-maven-3.0.1/boot/*.jar
  chmod 644 /usr/share/java/apache-maven-3.0.1/lib/*.jar
At this point, the new Maven is installed. But the command mvn is still linked to the old installation. The next step will fix this.

3. Link /usr/share/maven to /usr/share/java/apache-maven-3.0.1
Change directories:
  cd /usr/share
Remove the link to the old version of Maven:
  unlink maven
Replace the old link with a new soft link to the new Maven 3.0 installation:
  ln -s java/apache-maven-3.0.1 maven
Exit the root session:

Verify Installation
At this point, invoking Maven with the command mvn -v from the Terminal should call the newly installed version:
  bash-3.2$ mvn -v
  Apache Maven 3.0.1 (r1038046; 2010-11-23 02:58:32-0800)
  Java version: 1.6.0_22
  Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x" version: "10.6.5" arch: "i386" Family: "mac"
After successful installation, the directory structure should be:
  /usr/share/maven -> java/apache-maven-3.0.1
The Windows .bat files in the bin directory are not needed, but they don't hurt anything. The original archive downloaded to the Desktop can be safely removed now that Maven was upgraded successfully.

Alternative Installation Methods
If you are already using MacPorts, you can upgrade Maven using this simple command:
  sudo port install maven3
If you wish to install MacPorts, check the MacPorts installation page for more information. There are .dmg disk images available for Snow Leopard that make installation very easy.


  1. Thanks for the guide; it came in handy to night when I didn't have time to fiddle with trying to get it set up properly!

  2. Thank you very much, it worked like a charm!

  3. Thanks a lot, they should include this in the official maven docs :-)

  4. It's also possible to use the homebrew packaging system ( And do a "brew install maven"

  5. Great Post! Also works for 3.0.3 :)

  6. Yes I confirm it does work like charm, for 3.0.4 too