How To Set up Apache Maven on Centos 7

In this section from the Linux Tutorials, we want to teach you How To Set up Apache Maven on Centos 7.

Apache Maven is a software project management, and comprehension tool, based on the concept of a project object model, or POM. Maven can manage a project’s build, reporting, and documentation from a central piece of information. This is a quote directly from the Apache Maven project website.

A more comprehensive definition of Apache Maven is that Maven is a project management tool, which encompasses a project object model. It follows a set of standards, it includes a project life cycle, a dependency management system, and logic for executing plugin goals at defined phases in a life cycle.

How To Set up Apache Maven on Centos 7

To install Apache Maven on Centos 7, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.

Now you can follow the steps below to install the latest Apache Maven version on Centos 7. We’ll be downloading the latest release of Apache Maven from their official website.

Install OpenJDK on Centos 7

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

sudo yum update -y

Maven 3.3+ requires JDK 1.7 or above to be installed.  Use the command below to install the OpenJDK package on Centos 7:

sudo yum install java-1.8.0-openjdk

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

java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)

Install Apache Maven on Centos 7

You need to visit the Apache Maven downloads page and copy the link address of the binaries package. Next, use the wget command to download it on your server in the tmp directory:

wget -P /tmp

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

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

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

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

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

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

sudo vi /etc/profile.d/

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/

Load the Maven environment variables on Centos 7 with the following command:

source /etc/profile.d/

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

mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/maven
Java version: 1.8.0_332, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.1.1.el7.x86_64", arch: "amd64", family: "unix"

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


With Maven, your projects follow a consistent structure. Projects become IDE agnostic, by enforcing a consistent structure, which makes modifications easier in the future when new developers are introduced to the project.

Hope you enjoy this article about How To Set up Apache Maven on Centos 7.

You may be interested in this article about How To Install Apache Maven on Debian 11.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!