How to Install Apache Maven on CentOS 8

Install Apache Maven on CentOS 8

In this article, we will have explained the necessary steps to install and configure Apache Maven on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Apache Maven is free and open source, software project management and comprehension tool written in Java. Based on the concept of a project object model (POM), Maven can manage an entire project’s build. With Maven you can easily store documents, generate reports and documentation from a central piece of information.

Install Apache Maven CentOS 8

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf clean all
sudo dnf update

Step 2. Install Java.

Apache Maven requires Java to be installed on your system. To install OpenJDK 8 run following command in terminal:

sudo dnf install java-1.8.0-openjdk-devel

To verify that Java was successfully installed, run the following command:

$ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Step 3. Install Apache Maven.

First, download Apache Maven from official Apache release page. The latest Gradle version available is 3.6.3:


Now extract downloaded tar.gz file using following command:

tar -zxvf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3 /opt/maven

Step 4. Setup environment variables.

Next step is to configure the PATH environment variable to include the Gradle bin directory. To do so, open your text editor and create a new file named inside of the /etc/profile.d/ directory:

nano /etc/profile.d/

Add the following content:

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

Now load the environment variables in the current shell using the following command:

source /etc/profile.d/

Check whether the Apache Maven has been successfully configured on your system using the below command:

$ mvn -version

Apache Maven 3.6.3 (meilana343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 1.8.0_232, 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-80.11.2.el8_0.x86_64", arch: "amd64", family: "unix"

Congratulation, you have learned how to install and configure Apache Maven on CentOS 8. If you have any question, please leave a comment below.