How To Install Apache Maven CentOS 7 / RHEL 7

0

Apache Maven is a free and powerful software project management and comprehension tool, based on Project Object Model. With maven, you can efficiently manage a project’s build, reporting, and documentation from a central piece of information.

This post will help you install Apache Maven on CentOS 7.

Install Java

Java development kit is the essential requirement for Apache Maven. So, you need to install Java development kit (JDK) on your system.

Follow any one of the links below based on the operating system to install Oracle JDK on your system.

READ: How To Install Oracle Java 11 / 8 CentOS 7 / RHEL 7

OR

If you plan to use OpenJDK for Maven, then you can just use the YUM command on CentOS / RHEL to install the same.

yum -y install java-1.8.0-openjdk

Run the following command to verify the installation of Java.

java -version

Output:

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Install Apache Maven

You can now go to Apache maven’s official website to download the latest stable version of Maven or use the following command to download the Apache Maven v3.5.2.

yum -y install wget
wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz

Now extract the downloaded archive using the TAR command.

tar -zxvf apache-maven-3.6.0-bin.tar.gz
mv apache-maven-3.6.0 /opt/maven

Setup Environment Variables

After you have moved precompiled Apache Maven files on your system, you will need set the environments variables by creating a maven.sh file under /etc/profile.d/ directory.

vi /etc/profile.d/maven.sh

Add following content.

export JAVA_HOME=/usr/jdk-11.0.1
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
JAVA_HOME and M2_HOME will depend on JDK and Maven installation respectively.

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

source /etc/profile.d/maven.sh

Verify Maven Installation

Check whether the Apache Maven has been successfully configured on your system using the following command.

mvn -version

Output:

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /usr/jdk-11.0.1
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.14.4.el7.x86_64", arch: "amd64", family: "unix"

That’s All.

Further Reading

You might also like

How To Install Apache Maven CentOS 7 / RHEL 7

0