How to Install Maven on CentOS 7

Install Apache Maven 3.5 on CentOS 7

We’ll show you how to install Maven on CenOS 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. Installing Maven on CentOS 7 is fairly easy task, just carefully follow the steps bellow and you should have Maven installed on your CentOS 7 server in less then 10 minutes.

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

1. Update the system

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

ssh root@IP_adress -p port_number

and perform a full system update by typing the following command

yum -y update

2. 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)

3. Install and configure Maven on CentOS 7

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

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
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

4. 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

5. Check installed version

and check the installed version

mvn -v

That’s it, you have successfully installed Maven on CentOS 7. For installing Maven on Ubuntu 16.04 check this tutorial – HOW TO INSTALL MAVEN ON UBUNTU 16.04


How to Install Maven on CentOS 7If you use one of our CentOS VPS Hosting plans, you don’t have to install Maven on CentOS 7, you can simply ask our expert Linux admins to install Maven on your CentOS 7 server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on How to Install Maven on CentOS 7, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “How to Install Maven on CentOS 7”

  1. Why do we need 6 releaseserver
    sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
    for CentOS7 ?

    Reply

Leave a Comment