You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

This tutorial serves as a step by step guide on how to install Apache Maven on RHEL / CentOS 8. Apache Maven is a software project management and automation tool used for managing the Java project’s build, reporting, and documentation from a central piece of information.

For CentOS 7 / Fedora: Installing Latest Apache Maven on CentOS 7 / Fedora

For Debian / Ubuntu use: Install Latest Apache Maven on Ubuntu / Debian

The Apache Maven package is available on RHEL 8 upstream repositories. Run the command below as a user with sudo privileges.

sudo yum -y install @maven

Java will be installed as a dependency. Wait for the installation to finish then check the version of Apache Maven installed on your RHEL 8 system.

$ mvn --version
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-32.el8.x86_64", arch: "amd64", family: "unix"

All options are available on:

$ mvn -h

Testing Apache Maven on RHEL / CentOS 8

Create Maven projects directory:

mkdir ~/mvn-projects && cd ~/mvn-projects

Create your first project:

mvn archetype:generate \
-DartifactId=my-app \
-DarchetypeArtifactId=maven-archetype-quickstart \

Since this is the first run,  it may take a while to execute.  This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository.

$ tree my-app/
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── mycompany
│ └── app
│ └──
└── test
└── java
└── com
└── mycompany
└── app
11 directories, 3 files
  • The src/main/java directory contains the project source code
  • The src/test/java directory contains the test source
  • The file pom.xml is the project’s Project Object Model (POM).

The filepom.xml is the core of a project’s configuration in Maven. It contains the majority of information required to build a project.

Build the Project

To build your Project, run:

mvn package

The command line will print out various actions, and end with the following:

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Jab 24 22:14:10 EAT 2018
[INFO] Final Memory: 2M/6M
[INFO] ------------------------------------------------------------------------

That’s all. Read Official Maven Documentation for further learning.

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF