Install and Configure Apache Maven on Rocky Linux 8

This guide intends to teach you to Install and Configure Apache Maven on Rocky Linux 8.

Maven is a powerful project management tool that is based on POM (project object model). It is used for project build, dependency, and documentation. It simplifies the build process like ANT. But it is too much more advanced than ANT.
In short terms we can tell maven is a tool that can be used for building and managing any Java-based project. maven makes the day-to-day work of Java developers easier and generally helps with the comprehension of any Java-based project.

Steps To Install and Configure Apache Maven on Rocky Linux 8

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

In this guide, We’ll be downloading the latest release of Apache Maven from their official website.

Install OpenJDK on Rocky Linux 8

Maven 3.3+ requires JDK 1.7 or above to be installed on your Rocky Linux 8.

First, update your local package index with the following command:

sudo dnf update -y

Then, use the command below to install the OpenJDK package on Rocky Linux 8:

sudo dnf install java-1.8.0-openjdk -y

At this point, Verify your Java installation by checking its version:

java -version
Output
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)

Install Maven on Rocky Linux 8

You need to visit the Apache Maven downloads page and copy the link address of the binaries package.

Download Maven

Next, use the wget command to download it on your server in the tmp directory:

sudo wget https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz -P /tmp

At this point, you need to extract your downloaded file in the opt directory:

sudo tar xf /tmp/apache-maven-3.8.7-bin.tar.gz -C /opt

Now you should create a symbolic link that will point to the Maven installation directory on Rocky Linux:

sudo ln -s /opt/apache-maven-3.8.7 /opt/maven

Note: To upgrade your Maven installation, simply unpack the newer version and change the symlink to point to it.

Set up Maven Environment Variables

At this point, you should set up the Maven environment variables on Rocky Linux 8. To do this, use your favorite text editor to create a new file inside the /etc/profile.d directory:

sudo vi /etc/profile.d/maven.sh

Add the following content to the file:

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

When you are done, save and close the file.

Next, make your file executable with the following command:

sudo chmod +x /etc/profile.d/maven.sh

Load the Maven environment variables on Rocky Linux 8 with the following command:

source /etc/profile.d/maven.sh

At this point, you can verify your Maven installation by checking its version:

mvn -version
Output
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /opt/maven
Java version: 1.8.0_352, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el8_7.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-305.12.1.el8_4.x86_64", arch: "amd64", family: "unix"

That’s it. The latest version of Apache Maven is now installed on your Rocky Linux system.

Conclusion

At this point, you have learned to Install and Configure Apache Maven on Rocky Linux 8.

Hope you enjoy it. You may be like these articles too:

Fix PuTTY Server Refused Our Key Error

Install Postman on Rocky Linux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!