How To Install Apache Maven on Debian 9 / Ubuntu 16.04 / CentOS 7


Apache Maven is a free and powerful software project management and comprehension tool, based on Project Object Model. With maven, you can efficiently manage a project’s build, reporting, and documentation from a central piece of information.

This post will help you install Apache Maven on Debian 9 / Ubuntu 16.04 / CentOS 7.

Below tutorial is written in an assumption that regular (non-root) user with sudo privileges is setting up the Maven on the system.

Install Java

Java development kit is the essential requirement for Apache Maven. So, you need to install Java development kit (JDK) on your system.

Follow any one of the links below based on the operating system to install Oracle JDK on your system.

READ: READ: How to Install Oracle Java 8 on Debian 9

READ: READ: How to Install Oracle Java 8 on Ubuntu 16.04

READ: READ: How to install Oracle Java 8 CentOS 7 / RHEL 7


If you plan to use OpenJDK for Maven, then you can just use the apt command in Debian / Ubuntu and YUM command on CentOS / RHEL to install the same.

### Debian / Ubuntu ###

sudo apt-get -y install openjdk-8-jdk

### CentOS / RHEL ###

sudo yum -y install java-1.8.0-openjdk

Run the following command to verify the installation of Java.

$ java -version


java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Install Apache Maven

You can now go to Apache maven’s official website to download the latest stable version of Maven or use the following command to download the Apache Maven v3.5.2.

$ wget

Now extract the downloaded archive using the TAR command.

$ sudo tar -zxvf apache-maven-3.5.2-bin.tar.gz
$ sudo mv apache-maven-3.5.2 /opt/maven

Setup Environment Variables

After you have moved precompiled Apache Maven files on your system, you will need set the environments variables by creating a file under /etc/profile.d/ directory.

$ sudo vi /etc/profile.d/

Add following content.

export JAVA_HOME=/usr/jdk1.8.0_151/
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Now load the environment variables in the current shell using the following command.

$ source /etc/profile.d/

Verify Maven Installation

Check whether the Apache Maven has been successfully configured on your system using the following command.

$ mvn -version


Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /opt/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.11.1.el7.x86_64", arch: "amd64", family: "unix"

That’s All.

You might also like

How To Install Apache Maven on Debian 9 / Ubuntu 16.04 / CentOS 7