How to Install Apache Maven on CentOS 7

March 20, 2019

Introduction

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.

Article on how to install Apache Maven on CentOS 7.

Prerequisites

  • 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
check maven version

The following output confirms a successful install:

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
check java verion on centos

Step 2: Download Apache Maven for CentOS

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

sudo wget http://mirrors.ibiblio.org/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz –P /tmp
download maven source file

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/maven.sh.

1. Create and edit the configuration file by entering:

sudo vi /etc/profile.d/maven.sh

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.

configure apache maven environment

3. Modify the file permissions with the chmod command by entering the following:

sudo chmod +x /etc/profile.d/maven.sh

4. Then load the file with the command:

source /etc/profile.d/maven.sh

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.

Note: Our Knowledge Base also features other Maven installations:
How to Install Maven on Ubuntu
How to Install Maven on Windows
How to Install Maven on Debian

Conclusion

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

For more information about installation, or about beginner and intermediate tutorials, please check out the official Maven documentation.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How To Upgrade or Update CentOS 7.0/7.1/7.2/7.3/7.4/7.5 to CentOS 7.6
April 5, 2019

CentOS 7.6 is a minor update and was published in December 2018. It includes various minor updates and...
Read more
How to Install Apache Maven on Debian 9
March 21, 2019

Apache Maven is a project management tool for developing Java applications It resembles other Linux-based...
Read more
How to Install phpMyAdmin on CentOS 7
October 22, 2018

This guide is for users who have already configured a CentOS server and installed the Apache HTTP services...
Read more
How to Set or Change a Hostname in CentOS 7
October 21, 2018

This technical guide is for users who already have a server running the CentOS 7 operating system on a...
Read more