Apache Maven is a project management tool for developing Java applications designed to provide a comprehensive and easy-to-read status of a project. It also incorporates a POM (Project Object Model) approach, meaning that it uses standardized software libraries and plugins. These features help create a standard development environment for multiple teams.

This tutorial will walk you through installing Apache Maven on CentOS 7.

how to install apache maven on centos 7


  • A system running CentOS 7
  • Access to a user account with sudo or root privileges
  • Access to a terminal window/command line (Ctrl-Alt-F2)
  • The yum package manager, included by default
  • (Optional) The wget software utility

Option 1: Install Apache Maven on CentOS with Yum

1. Open a terminal window, and enter the following:

sudo yum install maven

Confirm the installation, and allow the process to complete. Maven should now be installed on your system.

2. Verify the installation by checking the Maven version:

mvn ––version

The following output confirms a successful install:

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T13:49:05-06:00) Maven home: /opt/maven 
Java version: 1.8.0_161, vendor: Oracle Corporation
 Java home: /usr/lib/jvm/java-1.8.0-openjdk- 
Default locale: en_GB, platform encoding: UTF-8

Note: At the time this article was written, the latest stable version of Apache Maven was 3.6.0. If you need an older version, you can check Maven’s release history.

Option 2: Install Latest Version of Maven

Sometimes the software version in the default repositories is older than the latest stable release from the developers. This section will walk you through the manual installation of Apache Maven on CentOS.

Step 1: Install Java Development Kit

Apache Maven requires the Java Development Kit. This guide uses the OpenJDK software package.

1. In a terminal window, enter the following:

sudo yum install java-1.8.0-openjdk-devel

Allow the process to complete.

2. Verify the installation by checking the Java version:

java –version

Step 2: Download Apache Maven For CentOS

Download the Maven source file to the /tmp directory with the command:

sudo wget –P /tmp

If you get an error “command not found,” you may be missing the wget software. Install it by entering:

sudo yum install wget

Extract the .tar.gz archive:

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

(Optional) Create a symbolic link by entering:

sudo ln –s /opt/apache-maven-3.6.0 /opt/maven

This step preserves the extracted directory but allows you to use /opt/maven as a shortcut to that directory.

Step 3: Configure Environment

Apache Maven works from a configuration file, /etc/profile.d/

1. Create and edit the configuration file by entering:

sudo nano /etc/profile.d/

2. Enter the following lines:

# Apache Maven Environmental Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export JAVA_HOME=/usr/lib/jvm/jre-openjdk

export M2_HOME=/opt/maven

export MAVEN_HOME=/opt/maven

export PATH=${M2_HOME}/bin:${PATH}

Save the file and exit.

3. Change the file permissions by entering the following: 

sudo chmod +x /etc/profile.d/

4. Then load the file with the command:

source /etc/profile.d/

Step 4: Verify Apache Maven Installation

To verify the installation of Apache Maven, use the command:

mvn ––version

The system should display Apache Maven 3.6.0 and Maven Home: /opt/maven.

Using Apache Maven

Maven was designed initially for Java projects. However, it can also be used to build and manage other programming languages, such as Ruby and C#.

One of the ways that Maven works is through the use of plugins. Maven can download libraries and plugins from a central repository and cache a local version. Most plugins are written to support Java. If you’re planning to use Maven to manage another programming language, you may need to write your own plugins for that language.


Great job, you have successfully installed Apache Maven on CentOS 7.

For more information about installation, or about beginner and intermediate tutorials, please see the official maven documentation.