[How To] Install Apache Maven in Linux, Solaris and Mac OS X

The Apache Maven tool is used to build Java projects. It is very important to set Maven environment variables in order to execute the Maven commands.

This post will explain how to set Maven environment variables in Linux.

1) Download Apache Maven binary archive under /opt partition from here

1
2
cd /opt
wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz

2) Extract the archive

1
tar -xzvf apache-maven-3.0.5-bin.tar.gz

3) Go to the extracted directory

1
cd apache-maven-3.0.5

4) Get current working directory

1
pwd

Output:

/opt/apache-maven-3.0.5

5) Set the Apache Maven environment variables for the current user

1
2
export M2_HOME=/opt/apache-maven-3.0.5
export PATH=${M2_HOME}/bin:${PATH}

To set the environment variables on server boot and for all the users, update either each user's bash_profile file or /etc/rc.local file.

6) Verify by running any maven command

1
mvn --version

Output:

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: /opt/apache-maven-3.0.5

Hope this helps! 🙂

Review Overview

User Rating: 4.9 ( 2 votes)
Share on Facebook2Share on Google+0Tweet about this on TwitterShare on StumbleUpon0Share on LinkedIn0Share on Tumblr0Pin on Pinterest2Email this to someonePrint this page

About Abhijit Sandhan

Abhijit Sandhan
Loves Linux, Blogging, Traveling, Hiking and sharing Knowledge!

Leave a Reply

Your email address will not be published. Required fields are marked *