Install Apache Maven on Rocky Linux 8

|
Last Updated:
|
|

In this tutorial, you will learn how to install Apache Maven on Rocky Linux 8. Apache Maven is a Java project management and project comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

Installing Apache Maven on Rocky Linux 8

There are three ways in which you can install Apache Maven.

  1. Install from the default Rocky Linux AppStream Repository
  2. Install latest release version of Maven using ready-made binary
  3. Build Maven from the source code (Beyond the scope of this tutorial)

Install Apache Maven from Repository

Maven is available on the default Rocky Linux 8 AppStream repositories.

dnf info maven
Available Packages
Name         : maven
Epoch        : 1
Version      : 3.5.4
Release      : 5.module+el8.3.0+133+b8b54b58
Architecture : noarch
Size         : 26 k
Source       : maven-3.5.4-5.module+el8.3.0+133+b8b54b58.src.rpm
Repository   : appstream
Summary      : Java project management and project comprehension tool
URL          : http://maven.apache.org/
License      : ASL 2.0 and MIT

The Maven packages provided by the AppStream repos may not be up-to-date. See for example, the current stable Maven releases version is Maven 3.8.1 as per the Maven release page.

If you however want to install this version, then you can run the command below;

dnf install maven -y

Once the installation is done, you check the version;

mvn --version

Sample output;

Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 11.0.12, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-305.10.2.el8_4.x86_64", arch: "amd64", family: "unix"

Install latest release version of Maven using ready-made binary

Install OpenJDK on Rocky Linux 8

If you want to install the latest release version of Maven using the ready-made binary, then you have to ensure OpenJDK 1.7++ is installed.

In this demo, we are going to use OpenJDK 11, which is the latest version provided by the AppStream repo as of this writing.

OpenJDK 11 can be installed on Rocky Linux 8 by running the command below;

dnf install java-11-openjdk

Install Apache Maven

Once OpenJDK is in place, you can download the binary from the downloads page.

Current version is v3.8.1. Hence, get the download link to the latest version and pull it. To download v3.8.1, then run the command below;

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

Extract the Maven Tarball

You can extract it to /opt or any other directory of your preference, since you will have to add the Maven binary directory to the current PATH.

We use /usr/local/maven in this demo.

mkdir /usr/local/maven
tar xzf apache-maven-3.8.1-bin.tar.gz -C /usr/local/maven/ --strip-components=1

Add the bin directory to your PATH

Update the PATH with the path to Maven binaries;

echo export 'PATH=$PATH:/usr/local/maven/bin/' > /etc/profile.d/maven.sh
chmod +x /etc/profile.d/maven.sh

Update also the path to JAVA_HOME;

echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64' >> /etc/profile.d/maven.sh

Source the variables path;

source /etc/profile.d/maven.sh

Verify that it is correctly installed

You can verify that Maven is installed correctly;

mvn --version
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /usr/local/maven
Java version: 11.0.12, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-305.10.2.el8_4.x86_64", arch: "amd64", family: "unix"

Getting Started with Apache Maven

You can now learn on how to use Maven on the getting started page, link provided below;

Maven Getting Started Guide

Other Tutorials

Install Latest Nodejs on Rocky Linux 8

Install Yarn on Rocky Linux 8

Install Python on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment