How to Install Apache Maven on CentOS 7

Apache Maven is a open source software project management and build automation tool, that is based on the conception of a project object model (POM), which is primarily used for deploying Java-based applications, but can also be used on projects written in C#, Ruby and other programming languages.

In this article, I will explain how to install and configure latest version of Apache Maven on a CentOS 7 system (the given instructions also works on RHEL and Fedora distribution).


  • A newly deployed or existing CentOS 7 server instance.
  • Java Development Kit (JDK) – Maven 3.3+ require JDK 1.7 or above to execute.

Install OpenJDK 8 in CentOS 7

Java Development Kit (JDK) is a primary requirement to install Apache Maven, so first install Java on CentOS 7 system from the default repository and verify the version using following commands.

# yum install -y java-1.8.0-openjdk-devel
# java -version

If installation went well, you see the following output.

openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

Install Apache Maven in CentOS 7

Next, go to the official Apache Maven download page and grab the latest version or use the following wget command to download it under the maven home directory ‘/usr/local/src’.

# cd /usr/local/src
# wget

Extract the downloaded archive file, and rename it using following commands.

# tar -xf apache-maven-3.5.4-bin.tar.gz
# mv apache-maven-3.5.4/ apache-maven/ 

Configure Apache Maven Environment

Now we need to configure the environments variables to pre-compiled Apache Maven files on our system by creating a configuration file ‘’ in the ‘/etc/profile.d’ directory.

# cd /etc/profile.d/
# vim

Add the following configuration in ‘’ configuration file.

# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export M2_HOME=/usr/local/src/apache-maven
export PATH=${M2_HOME}/bin:${PATH}

Now make the ‘’ configuration file executable and then load the configuration by running the ‘source’ command.

# chmod +x
# source /etc/profile.d/

Check Apache Maven Version

To verify Apache Maven installation, run the following maven command.

# mvn --version

And you should get a output similar to the following:

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T19:33:14+01:00)
Maven home: /usr/local/src/apache-maven
Java version: 9.0.4, vendor: Oracle Corporation, runtime: /opt/java/jdk-9.0.4
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.17.6-1.el7.elrepo.x86_64", arch: "amd64", family: "unix"

That’s It! You have successfully installed Apache Maven 3.5.4 on your CentOS 7 system. If you have any problems related to installation, do share with us in the comment section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

6 Responses

  1. kassim says:

    A very good article, helped me to install Maven on CentOS without any problems…

  2. Rama SubbaReddy says:

    Nice article which helped a lot to install mvn and java quickly on centos7 version.

  3. Andrici Cristina says:

    I have no file “” under /etc/profile.d/ directory.

    I cannot go further.

    Please help me..

    • Dmytro says:

      Cristina, this file had to be created, but really you don’t need it. Do the same thing simpler way:

      $ sudo nano /etc/environment  #this opens the configuration file

      Add lines:

      Press Ctrl+O to save changes and Press Ctrl+X to quite.
      Run a command.
      $ source /etc/environment to reload

      Now you can check the effect with:

      $ mvn --version
    • mani says:

      Hi Bro, file is not there, we need to create it.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.