Getting Maven on Rocky Linux 9

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

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-11.0.18.0.10-2.el9_1.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-162.18.18.1.el9_1.x86_64", 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-11.0.18.0.10-2.el9_1) (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.18.0.10-2.el9_1) (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.

wget https://downloads.apache.org/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz

Unzip

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/maven.sh

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/maven.sh
source /etc/profile.d/maven.sh

Finally, check the installed version

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

Conclusion

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

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook