How To Install Apache Maven CentOS 7 / RHEL 7

0

Apache Maven is a free and powerful software project management and comprehension tool. It is based on the Project Object Model.

With maven, you can efficiently manage a project’s build, reporting, and documentation from a central piece of information.

In this post, we will see how to install Apache Maven on CentOS 7 / RHEL 7.

Install Java

Java development kit is the essential requirement for Apache Maven. So, you need to install the 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 to install it.

yum -y install java-1.8.0-openjdk-devel

Run the following command to verify the installation of Java.

java -version

Output:

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, 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.6.3.

yum -y install wget

wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Now extract the downloaded archive using the TAR command.

tar -zxvf apache-maven-3.6.3-bin.tar.gz

mv apache-maven-3.6.3 /opt/maven

Setup Environment Variables

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

vi /etc/profile.d/maven.sh

Add the following content.

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
JAVA_HOME and M2_HOME will depend on JDK and Maven installation.

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.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 1.8.0_232, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.9.1.el7.x86_64", arch: "amd64", family: "unix"

Conclusion

That’s All. You have successfully installed Apache Maven on CentOS 7 / RHEL 7.

You might also like