Monday, August 9, 2010

Updating to Maven 2.2.1 in Mac OS X Snow Leopard

Mac OS X 10.6.4 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_20
  Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac
To manually upgrade to Maven 2.2.1, complete these 3 steps:
  1. Download Maven 2.2.1 archive
  2. Unpack archive into /usr/share/java/
  3. Link /usr/share/maven to /usr/share/java/apache-maven-2.2.1
Below are the details of each step.

1. Download Maven 2.2.1 archive
Go to the Maven download site and download the file named “apache-maven-2.2.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-2.2.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-2.2.1:
  tar xzf apache-maven-2.2.1-bin.tar.gz
Remove the archive file - it is no longer needed:
  rm apache-maven-2.2.1-bin.tar.gz
Remove quarantine status from trusted Maven installation files:
  xattr -dr apache-maven-2.2.1/
If the mvn or mvnDebug binaries are not already executable (they should be), you can make sure they are with these commands:
  chmod 755 /usr/share/java/apache-maven-2.2.1/bin/mvn
  chmod 755 /usr/share/java/apache-maven-2.2.1/bin/mvnDebug
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-2.2.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 2.2.1 installation:
  ln -s java/apache-maven-2.2.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 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
  Java version: 1.6.0_20
  Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
  Default locale: en_US, platform encoding: MacRoman
  OS name: "mac os x" version: "10.6.4" arch: "i386" Family: "mac"
After successful installation, the directory structure should be:
  /usr/share/maven@ -> java/apache-maven-2.2.1
The .bat files in the bin directory are not really 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 maven2
If you wish to install MacPorts, check the MacPorts installation page for more information about installing MacPorts. There are .dmg disk images available for Snow Leopard that make installation very easy.


  1. Thank you for this tutorial. It's now updated on my mac!

  2. thank you, this was very straight forward and easy!

  3. didn't work for me :(
    mvn still invokes maven 2.2.0
    something with the link I assume...

  4. oh, it *does* work. it was just the modifications that the liftweb installer had made to .bash_profile that overrode the link. thanks for your instructions! :)

  5. For instructions on upgrading to Maven 3.0, check my updated post.

  6. Instruction are simple and easy to install maven.I must thank for your blog

  7. hi...Im student from Informatics engineering nice article,
    thanks for sharing :)