How to Install Apache Maven on CentOS 7

r00t April 17, 2018

Install Apache Maven on CentOS 7

In this tutorial we’ll learn how to install Apache Maven on CentOS 7. We will also install and configure its prerequisites. Apache Maven is a project management tool for handling, construction, reporting and documenting of Java-based improvement project. It comprises a project object model, a set of criteria, a project lifecycle, a dependency management system and logic. Maven is designed to provide a simple project set up for users to have an easy environment.Maven addresses two parts of building a program, it first clarifies the way the software is assembled and second its dependencies.

I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache Maven on CentOS 7

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

yum -y install epel-release
yum -y update

Step 2. Installing Java.

Apache Maven requires Java 1.7 or greater. For this reason, you can install OpenJDK 8 as follows:

yum install -y java-1.8.0-openjdk-devel

Once installed, run the following command the check the installed version:

### java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

Step 3. Installing Apache Maven.

First, Go to their official website and download the arhive of the desired version. In this tutorial we will install Apache Maven version 3.5:

wget http://mirrors.sonic.net/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.zip

Unpack the downloaded zip archive:

unzip apache-maven-3.5.3-bin.zip
mv apache-maven-3.5.3 maven
rm -f apache-maven-3.5.3-bin.zip

Create a version-irrelevant symbolic link pointing to the original Apache Maven 3.5 directory:

nano /etc/profile.d/maven.sh
export PATH=/opt/maven/bin:${PATH}

With this step Apache Maven should be successfully installed and configured on your CentOS 7 VPS. Run the following command to confirm:

### mvn -version
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-1.8.0.161-0.b14.el7_4.x86_64/jre
Default locale: en_GB, platform encoding: UTF-8

Congratulation’s! You have successfully install Apache Maven on your CentOS 7 server. Thanks for using this tutorial for installing Apache Maven on CentOS 7 system.

The Tags:

Leave a Comment

Comments are closed.