Install Maven in Rocky Linux 9 [Step-by-Step]


Rocky Linux

Author: Omer Cakmak
Reviewer: Deepak Prasad

Apache Maven is an open source software project management and understanding tool distributed with Apache License 2.0. Maven is based on the project object model (POM) concept. It can manage the construction, reporting and documentation of a project from a central piece of information. With Maven, you can create and manage projects written in Java, C#, Ruby, Scala and other languages.

In this article, we will install Maven on Rocky Linux 9. You can also check 50 questions and answers about Maven.

 

Different methods to install Maven

Rocky Linux 9 package repositories include the Maven package. You can install quickly and easily. If you want, you can manually install the current version on the official page. Rocky Linux 9 package repositories include the Maven package. You can install quickly and easily. If you want, you can manually install the current version on the official page.

 

Method-1: Install Maven from the package repository

This installation method is fast and provides stable package usage. Run the following command in terminal to start the maven installation:

[foc@rocky9 ~]$ sudo dnf -y install maven

Maven package installation is complete.  Let's check the Maven version:

[foc@rocky9 ~]$ mvn --version
Apache Maven 3.6.3 (Red Hat 3.6.3-14)
Maven home: /usr/share/maven
Java version: 11.0.16, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.el9_0.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-70.13.1.el9_0.x86_64", arch: "amd64", family: "unix"

Maven needs OpenJDK package. With the Maven installation from the repository, this package is also installed. The version is as follows:

[foc@rocky9 ~]$ java --version
openjdk 11.0.16 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.el9_0) (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.el9_0) (build 11.0.16+8-LTS, mixed mode, sharing)

Now let's move on to the other installation method.

 

Method-2: Install Maven from Source

The current version of Apache Maven is 3.8.6. You can install this version or any other version you want with this method. Maven uses Java. Let's install the current java package for current Maven and your other package needs:

[foc@rocky9 ~]$ sudo dnf install wget tar java-17-openjdk.x86_64 -y

Copy the link of the version you want to install and add it after the wget command:

[foc@rocky9 ~]$ wget https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
--2022-09-23 00:36:27-- https://archive.apache.org/dist/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
Resolving archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
Connecting to archive.apache.org (archive.apache.org)|138.201.131.134|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8676320 (8.3M) [application/x-gzip]
Saving to: ‘apache-maven-3.8.6-bin.tar.gz’

apache-maven-3.8.6-bin.tar.gz 100%[===============================================>] 8.27M 2.67MB/s in 3.1s

2022-09-23 00:36:30 (2.67 MB/s) - ‘apache-maven-3.8.6-bin.tar.gz’ saved [8676320/8676320]

Let's extract the tar.gz file you downloaded under /opt:

[foc@rocky9 ~]$ sudo tar -xvf apache-maven-3.8.6-bin.tar.gz -C /opt

Let's create a symbolic link for the maven file with an easier name. This will provide us with ease of use:

[foc@rocky9 ~]$ sudo ln -s /opt/apache-maven-3.8.6 /opt/maven

Create an environment file for Maven and define the following information:

[foc@rocky9 ~]$ sudo touch /etc/profile.d/maven
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Give execute permission to the environment file:

[foc@rocky9 ~]$ sudo chmod +x /etc/profile.d/maven

Load the environment variable using the following command:

[foc@rocky9 ~]$ source /etc/profile.d/maven

Finally check the Maven version:

[foc@rocky9 ~]$ mvn --version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /opt/maven
Java version: 17.0.4, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.4.0.8-2.el9_0.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.14.0-70.13.1.el9_0.x86_64", arch: "amd64", family: "unix"

Congratulations, the current Maven installation is complete.

 

Summary

We think this article is helpful for Maven installation. You can get information from the official website for Maven plugins, extensions and more. On your local server, the following commands will inform you:

[foc@rocky9 ~]$ mvn --help

usage: mvn [options] [<goal(s)>] [<phase(s)>]

Or:

[foc@rocky9 ~]$ man mvn

NAME
mvn - software project management and comprehension tool

DESCRIPTION
usage: mvn [options] [<goal(s)>] [<phase(s)>] usage: mvnDebug [options] [<goal(s)>] [<phase(s)>]

 

References

maven.apache.org - Installing Apache Maven

 

Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment