There are wide differences between operating systems such as Mac OS X and Microsoft Windows, and there are subtle differences between different versions of Windows. Luckily, the process of installing Maven on all of these operating systems is relatively painless and straightforward. The following sections outline the recommended best-practice for installing Maven on a variety of operating systems.
You can download a binary release of Maven from http://maven.apache.org/download.html.
Download the current release of Maven in a format that is convenient for
you to work with. Pick an appropriate place for it to live, and expand
the archive there. If you expanded the archive into the directory
/usr/local/apache-maven-2.2.1, you may
want to create a symbolic link to make it easier to work with and to
avoid the need to change any environment configuration when you upgrade
to a newer version:
/usr/local % cd /usr/local /usr/local % ln -s apache-maven-2.2.1 maven /usr/local % export M2_HOME=/usr/local/maven /usr/local % export PATH=${M2_HOME}/bin:${PATH}
Once Maven is installed, you need to do a couple of things to make
it work correctly. You need to add its bin directory in the distribution (in this
example, /usr/local/maven/bin) to
your command path. You also need to set the environment variable
M2_HOME to the top-level directory you installed (in
this example, /usr/local/maven).
Note
Installation instructions are the same for both
OSX Tiger and OSX Leopard. It
has been reported that Maven 2.0.6 is shipping with a preview release
of XCode. If you have installed XCode, run mvn from
the command-line to check availability. XCode installs Maven in
/usr/share/maven. We recommend installing the
most recent version of Maven 2.2.1 as there have been a
number of critical bug fixes and improvements since Maven 2.0.6 was
released.
You'll need to add both M2_HOME and
PATH to a script that will run every time you login. To
do this, add the following lines to
.bash_login.
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
Once you've added these lines to your own environment, you will be able to run Maven from the command line.
Note
These installation instructions assume that you are running bash.
If you are using MacPorts, you can install the maven2 port by executing the following command-line:
$ sudo port install maven2
Password: ******
---> Fetching maven2
---> Attempting to fetch apache-maven-2.2.1-bin.tar.bz2
from http://www.apache.org/dist/maven/binaries
---> Verifying checksum(s) for maven2
---> Extracting maven2
---> Configuring maven2
---> Building maven2 with target all
---> Staging maven2 into destroot
---> Installing maven2 2.2.1_0
---> Activating maven2 2.2.1_0
---> Cleaning maven2
For more information about the maven2 port, see the maven2
Portfile.
For more information about MacPorts and how to install it, see the
MacPorts project
page.
Installing Maven on Windows is very similar to installing
Maven on Mac OSX, the main differences being the
installation location and the setting of an environment variable. This
book assumes a Maven installation directory of c:\Program
Files\apache-maven-2.2.1, but it won't make a
difference if you install Maven in another directory as long as you
configure the proper environment variables. Once you've unpacked Maven
to the installation directory, you will need to set two environment
variables—PATH and M2_HOME. To set these
environment variables from the command-line, type in the following
commands:
C:\Users\tobrien > set M2_HOME=c:\Program Files\apache-maven-2.2.1 C:\Users\tobrien > set PATH=%PATH%;%M2_HOME%\bin
Setting these environment variables on the command-line will allow you to run Maven in your current session, but unless you add them to the System environment variables through the control panel, you'll have to execute these two lines every time you log into your system. You should modify both of these variables through the Control Panel in Microsoft Windows.
To install Maven on a Linux machine follow the exact procedure outlined in Section 2.3.1, “Installing Maven on Mac OSX”.
To install Maven on a FreeBSD or OpenBSD machine, follow the exact procedure outlined in Section 2.3.1, “Installing Maven on Mac OSX”.
