how to install maven on linux

This article will help you to install Maven on Linux Operating System.

What is Apache Maven?

Apache Maven is a software project management and comprehension tool. 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.

Prerequisites: 

Maven 3.3 requires JDK 1.7 or above to execute – it still allows you to build against 1.3 and other JDK versions by Using Toolchains

Install Maven on Linux

RHEL/CentOS/Fadora Installation

sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version

Alternate Way:

wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.1-bin.tar.gz
sudo tar xzf apache-maven-3.2.1-bin.tar.gz -C /usr/local
cd /usr/local
sudo ln -s apache-maven-3.2.1 maven

Setup Maven Path:

Create maven.sh under profile.d define maven path and append it in PATH env variable.

sudo vi /etc/profile.d/maven.sh

and add below lines:

export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Load the environment variable in current shell

source /etc/profile.d/maven.sh

Verify the installation

mvn -version
(Visited 131 times, 3 visits today)