How To Install Apache Maven Rocky 8 / CentOS 8 / RHEL 8


Apache Maven is a free and powerful build automation tool primarily used for Java projects. It is based on the Project Object Model. You can efficiently manage a project’s build, reporting, and documentation with maven.

Maven can also build and manage projects written in C#, Ruby, Scala, and other languages.

This post will help you install Apache Maven on Rocky 8 / CentOS 8 / RHEL 8.

Install Java

For Apache Maven to build projects, installing the Java Development Kit (JDK) is an essential requirement. Therefore, it is recommended that you install either the Oracle JDK or OpenJDK 8+ on your system.

READ: How To Install Oracle Java Rocky 8 / CentOS 8 / RHEL 8


If you plan to use OpenJDK for Maven, then you can use the DNF command to install it.

dnf install -y java-1.8.0-openjdk-devel

Verify the JDK installation with the below command.

java -version


openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b09)
OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)

Install Apache Maven

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

dnf install -y wget


Then, extract the downloaded archive using the tar command and then move them to the desired location.

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

mv apache-maven-3.9.1 /opt/maven

Setup Environment Variables

We will now set the environment variables for Maven 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.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /opt/maven
Java version: 1.8.0_362, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-425.13.1.el8_7.x86_64", arch: "amd64", family: "unix"


That’s All. I hope you learned how to install Apache Maven on Rocky 8 / CentOS 8 / RHEL 8.

You might also like