Install Apache Maven 3.5 on CentOS 7

Install Apache Maven 3.5 on CentOS 7

 

Apache Maven is free and open source java based software for project management and comprehension tool. Maven allows users to easily store documents, generate reports and documentation from a central piece of information. In this tutorial we will guide you through the steps of installing Apache Maven 3.5 on CentOS 7.

Listed below are some of the key features of Apache Maven:
– Simple project setup that follows best practices
– Superior dependency management
– Extensible with a lot of plugins written in Java or other scripting languages
– Model based builds
– Release management and distribution publication:

and in the latest Maven 3.5 version, there are lots of bug fixes and important changes such as:
– ANSI colors added to the console
– Fixed several bugs in MVN scripts regarding spaces, quotations and special characters.
– Switch from Eclipse Aether to Maven Artifact Resolver
– and much more

Update the system

To start with the Maven installation, log in to your CentOS 7 server via SSH as user root

ssh [email protected]_adress -p port_number

and perform a full system update by typing the following command

yum -y update

Install Java 8

Since Maven is Java based application we have to install Java on the server. Java version 1.7 or newer is required. We will install Java 8

yum install -y java-1.8.0-openjdk-devel

This command will install Java 8 and all necessary dependencies.

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)

Install and configure Maven 3.5

Apache Maven’s installation is a simple process. Go to their official website and download the arhive of the desired version. In this tutorial we will install Apache Maven version 3.5.3

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

yum -y install unzip
cd /opt
unzip apache-maven-3.5.3-bin.zip

Rename the newly created directory and remove the downloaded archive

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

We downloaded the precompiled version of Apache Maven, so we have to set the environment variables. Create the following file

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

Save the file and load the environment variables in the current shell.

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

mvn -version

and you should get the following output

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

Install Apache Maven from a repository

Apache Maven can be also installed by adding its repository to the server. Please note that this will not install the latest available version Download its official repository

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sed -i s/$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo

and install Maven with the yum package manager

yum install -y apache-maven

and check the installed version

mvn -v

Original Article