[How To] Install Apache Maven in Linux, Solaris and Mac OS X
The Apache Maven is build tool used in Java projects for build automation. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information
This post will explain steps to install Apache Maven & setup Apache Maven environment variables in Linux, Solaris & Mac OS X operating systems.
Steps to Install & Setup Apache Maven on Linux (distributions like RHEL, CentOS, Ubuntu, Fedora) , Solaris & Mac OS X
Step 1. Download the Apache Maven binary
Navigate to /tmp partition & download Apache Maven binary present in various format binart in zip / tar.gz / from official Apache Maven website here :
cd /opt
wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
Step 2. Extract the downloaded Apache Maven archive
Extract the download archive and copy it into /opt partition on the server:
tar -xzvf apache-maven-3.0.5-bin.tar.gz
mv apache-maven-3.0.5/ /opt/ -aR
Step 3. Get the Apache Maven installation path
Go to the Apache maven directory:
cd apache-maven-3.0.5
Get current working directory using below command:
pwd
Output:
/opt/apache-maven-3.0.5
Step 4. Setup Apache Maven environment variables
Copy the output path as in step 3 which is value of the M2_HOME as below:
export M2_HOME=/opt/apache-maven-3.0.5
export PATH=${M2_HOME}/bin:${PATH}
To set the Apache Maven environment variables only for current terminal, set the Apache Maven installation directory variable M2_HOME using export. Post that, set Apache Maven bin folder path into PATH variable.
To set the Apache Maven environment variables on server boot for all the users permanently, update /etc/rc.local file with the above export entries.
To set the Apache Maven environment only for specific user permanently, update respective user's .bash_profile file with the above export entries.
Verify by checking the variable value using below command:
echo $M2_HOME
echo $PATH
Step 5. Verify Apache Maven environment variable setup
Verify by running any Apache maven command to show version from terminal using below command:
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! 🙂