How To Install Apache Maven CentOS 7 / RHEL 7


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


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


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


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 file under /etc/profile.d/ directory.

vi /etc/profile.d/

Add the following content.

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-
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/

Verify Maven Installation

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

mvn -version


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-
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"


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

You might also like