Installing Maven on Mac OS X

Maven is a popular tool for building software applications according to a standard layout. We will learn more about Maven and how it works later. For now, let’s get Maven installed on Mac OS X and up and running.

Mac OS X comes pre-installed with a Maven installation so in most cases you won’t need to install Maven yourself. So, before you begin installing Maven, open a TERMINAL window and check if you have it already installed.

$ mvn –version
Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java version: 1.6.0_24, vendor: Apple Inc.
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.7″, arch: “x86_64″, family: “mac”

If your mac does not come with a Maven installation…

If you didn’t see anything exciting happen when you entered “mvn –version” then you probably do not have maven installed. Not to worry, here is how to install it:

1. Download Maven

Go to the maven website and get a version of Maven. I found that when I was installing my own version of Maven, the version 2.2.1 worked the best with the various tutorial examples I was downloading all over the internet. However, my new Mac OS X comes pre installed with Maven 3 and it works great :-)

I downloaded apache-maven-2.2.1-bin.zip.

2. Install Maven

You can “install” maven by unzipping the folder “apache-maven-2.2.1″ and moving it manually in Finder to Macintosh HD/usr/local

Can’t find your usr folder inside your Macintosh HD? You need to show your hidden files!

Open a new TERMINAL window and enter the following:

$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder

3. Set environment variables and verify installation

Now go into TERMINAL and make sure it is there.

$ cd /usr/local
$ ls
(should list apache-maven-2.2.1)
$ export M2_HOME=/usr/local/apache-maven-2.2.1
$ export M2=$M2_HOME/bin
$ export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/home
$ export PATH=$M2:$JAVA_HOME/bin:$PATH
$ mvn –version

Note: there are other ways of setting environment variables. Please refer to the tutorial “Environment variables” for more information.

0 Comments

Post a Comment

(required):