How to install Maven on Mac OS X ?

There are many ways to install Apache Maven on Mac OS X. You can use Homebrew, MacPorts or just download it and set up manually. For the sake of this tutorial I will use Apache Maven 3.0.5 and JDK version 1.7.0_25, I'm using Mountain Lion.

There are a few steps which you need to perform:
  1. Check your JDK installation. If you don't have JDK, you will need to install one (1.5 or above).
  2. Install Apache Maven 3.0.5.
  3. Test your installation.

1. Check/Install JDK

To check if you have Java installed just type this in your terminal:



You should get the following result if Java is installed:


java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

I'm using Java 1.7.0_25. To make sure that you have installed both JDK and JRE, not only JRE, an additional check should include javac (Java compiler). Type which javac in your terminal and you should get a path to your Java compiler, which looks like this: /usr/bin/javac. If output is empty it means that you don't have JDK installed - go to If JDK is not present step.

If JDK is not present:

 

command not found: java
 or: empty which result.

Let's install JDK:

  1. Go to JDK download page.
  2. Download JDK for Mac OS X x64 (you will have to accept licence agreement first).
  3. Install JDK like a normal DMG file.

2. Install Apache Maven

I'm going to describe tree different methods: Homebrew, MacPorts, manually.

Install Apache Maven with Homebrew

 


Install Apache Maven with MacPorts


Install Apache Maven manually

  1. Download Apache Maven 3.0.5:
  2. Extract it:
  3. Go to /usr/local:
  4. Create a symbolic link to your apache-maven-3.0.5-bin directory:
  5. Export variables (probably you'll want to put these commands in ~/.profile or other shell startup script):

3. Test Apache Maven installation

To test if maven is properly installed on your computer just put: in your shell. You will get information about Maven installation or command not found - it depends on the result of the installation process.

Example output (Apache Maven installed with Homebrew):

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: /usr/local/Cellar/maven/3.0.5/libexec
Java version: 1.6.0_51, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: pl_PL, platform encoding: MacCentralEurope
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"
 

2 comments :: How to install Maven on Mac OS X ?

  1. I've just realized that SyntaxHighlighter (I belive by Alex Gorbatchev) is not working on iOS (Safari). At least for mobile version of this site (this is blogger.com blog).

    Sorry for technical problems. I will stop using this tool.

    Best Regards,
    Michael Flowersky

  2. ADDITIONAL INFORMATION: Maven came pre installed since version 10.6.8 Mac OS X Snow Leopard.

Post a Comment