I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

Getting Maven on Rocky Linux 9

Hello, friends. In this post, you’ll learn how to install Apache Maven on Rocky Linux 9 / Alma Linux 9

Apache Maven is a project management software, and we can say that it is also a Java dependency manager. It is based on the POM concept, where all project management rules are defined.

Maven simplifies the tasks of compiling and building software applications, mainly used with programming languages that are intended to run on the Java Virtual Machine (JVM).

So let’s get started.

Installing Apache Maven on Rocky Linux 9 / Alma Linux 9

Method 1: Install Maven from the official repositories

Apache Maven is an important tool for Java developers, so it is no coincidence that it is present in the official repositories of this distribution.

So, you can also install it this way.

First, open a terminal and update the system

sudo dnf update

Then, you can run

sudo dnf install maven
Install Maven on Rocky Linux 9 / Alma Linux 9
Install Maven on Rocky Linux 9 / Alma Linux 9

As you can see, DNF will take care of all the dependencies, including Java.

When the process is finished, you can check the installed version with the following command

mvn --version

Sample output:

Apache Maven 3.6.3 (Red Hat 3.6.3-14)
Maven home: /usr/share/maven
Java version: 11.0.18, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-", arch: "amd64", family: "unix"

Method 2: Getting the latest stable version of Maven

The previous method does not provide the latest stable version of Maven, so we have to do a manual installation.

To achieve this, first install Java, which is a dependency of it

sudo dnf install java-11-openjdk-devel

Check the Java version

java --version

Sample output:

openjdk version "11.0.18" 2023-01-17 LTS
OpenJDK Runtime Environment (Red_Hat- (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM (Red_Hat- (build 11.0.18+10-LTS, mixed mode, sharing)

Next, download the latest stable version of Maven. As of today, it is 3.9.1.



sudo tar xvzf apache-maven-3.9.1-bin.tar.gz -C /opt

Rename the folder

sudo mv /opt/apache-maven-3.9.1 /opt/maven

Next, it is necessary to configure the environment variables so that the system recognizes Maven without problems.

sudo nano /etc/profile.d/

And add the following

export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Save the changes and close the editor,

Now apply the changes by giving it run permissions and refreshing the file.

sudo chmod +x /etc/profile.d/
source /etc/profile.d/

Finally, check the installed version

mvn --version
Latest version of Maven
Latest version of Maven


Maven is vital for Java projects, and now you know how to install it on Rocky Linux 9 / Alma Linux 9.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook