Maven by Example
   - 2.3. Installing Maven

2.3. Installing Maven

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.

2.3.1. Installing Maven on Linux, BSD and Mac OS X

Download the current release of Maven from http://maven.apache.org/download.html. Choose 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-3.0.5, 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-3.0.5 maven
/usr/local % export PATH=/usr/local/maven/bin:$PATH

Once Maven is installed, you need to add its bin directory in the distribution (in this example, /usr/local/maven/bin) to your command path.

You’ll need to add the PATH configuration to a script that will run every time you login. To do this, add the following lines to .bash_login or .profile.

export PATH=/usr/local/maven/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.

2.3.2. Installing Maven on Microsoft Windows

Installing Maven on Windows is very similar to installing Maven on Mac OS X, 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-3.0.5, but it won’t make a difference if you install Maven in another directory as long as you configure the proper environment variable. Once you’ve unpacked Maven to the installation directory, you will need to update the PATH environment variable:

C:\Users\tobrien > set PATH="c:\Program Files\apache-maven-3.0.5\bin";%PATH%

Setting this environment variable on the command line will allow you to run Maven in your current session. Unless you add them to the System or User 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.

Setting Environment Variables

  • Go into the Control Panel
  • Select System
  • Go in Advanced tab and click on Environment Variables.
  • Click on the Path variable in the lower System variables section and click the Edit button.
  • Add the string "C:\Program Files\apache-maven-3.0.5\bin;" in the Variable value field to the front of the existing value and click on the OK button in this and the following dialogs.











Become a Member

Are you a current user of:

Top