How To Install Apache Maven on CentOS/RHEL 8/7

Channel: Linux
Abstract: Step 4 – Check Maven Version Apache Maven has been successfully configured on your system. Use the following command to check the version of installed

Apache Maven is a software project management and comprehension tool. 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 8/7 and Fedora 31/30/29 systems.

You may like:

  • How to Install Gradle on CentOS 8
Step 1 – Prerequisite

Java development kit is the primary requirement of Apache Maven. So you need to install the Java development kit (JDK) on your system. Make sure you have installed JDK, not JRE. se following command to install it.

yum install java-11-openjdk

Verify installed Java version on your system.

java -version 

openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10-LTS, mixed mode, sharing)

If you don’t have Java Development Kit installed on your system. Visit Install Java 11 on CentOS/RHEL 7/6 and Fedora

Step 2 – Install Apache Maven

After verifying java version on your system. Download Apache Maven from its official website or use the following command to download Apache Maven 3.6.2.

cd /opt
wget https://www-us.apache.org/dist/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz

Now extract downloaded archive using following command.

sudo tar xzf apache-maven-3.8.5-bin.tar.gz
sudo ln -s apache-maven-3.8.5 maven
Step 3 – Setup Environment Variables

As you have downloaded precompiled Apache Maven files on your system. Now set the environments variables by creating new file /etc/profile.d/maven.sh.

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

and add the following content.

export M2_HOME=/opt/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 Maven Version

Apache Maven has been successfully configured on your system. Use the following command to check the version of installed Maven on your system.

mvn -version

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/maven
Java version: 11.0.6, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-11.0.6.10-0.el8_1.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-147.3.1.el8_1.x86_64", arch: "amd64", family: "unix"

Finally, remove the downloaded archive file from the system to free disk space.

rm -f apache-maven-3.8.5-bin.tar.gz

Ref From: tecadmin

Related articles