Maven: How To Install Maven (Apache Maven) on CentOS 7(RHEL)

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. This tutorial will help you to install Apache Maven on your CentOS/RHEL.

Step 1 – Install Prerequisites (Install Java)

Java is the primary requirement of Apache Maven. So you need to install Java on your system. Make sure you have installed JDK, not JRE. For java installation visit how to install java on centos.

$ java -version

java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Step 2 – Install Apache Maven

Download Apache maven from its official website or use following command to download Apache Maven 3.5.2 and extract downloaded archive.

$ cd /usr/local
$ wget http://www-eu.apache.org/dist/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz

# Extract Apache maven archive
$ sudo tar xzf apache-maven-3.5.2-bin.tar.gz
$ sudo ln -s apache-maven-3.5.2 maven

Step 3 – Setup Environment Variables

Now set the environments variables by creating new file /etc/profile.d/maven.sh and load the environment variables in current shell using source command.

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

# Add following content into above maven.sh file
$ export M2_HOME=/usr/local/maven
$ export PATH=${M2_HOME}/bin:${PATH}

Now load the environment variables in current shell using following command.

$ source /etc/profile.d/maven.sh

Step 4 – Check installed Apache Maven Version

Use following command to check version of Maven.

$ mvn -version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-11-23T13:28:13+05:30)
Maven home: /usr/local/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_151/jre
Default locale: en_IN, platform encoding: UTF-8

References:
https://maven.apache.org/index.html
https://tecadmin.net/install-apache-maven-on-centos/

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

Leave a Reply