Apache Maven is a software project management and comprehension tool. Maven can manage a project’s build, reporting, and documentation from a central piece of information. This tutorial will help you to install Apache Maven on Debian 11, Debian 10, Debian 9, and Debian 8 systems.

Advertisement

You may like:

Prerequisites

Login to your Debian system using shell access. For the remote systems connect over SSH connection.

ssh root@debian

Run the below commands to upgrade the current packages to the latest version.

sudo apt update 
sudo apt upgrade

Step 1 – Install Java

Apache Maven required Java to be installed on your system. I have installed latest Java 11 on my Debian system using this tutorial.

java -version 

java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

Step 2 – Installing Maven on Debian

After the installation of Java. You are ready to install Apache Maven on Debian. Download the Apache maven archive file from its official website or use the following command to download Apache Maven 3.6.3.

cd /usr/local
wget https://www-us.apache.org/dist/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz

Extract the downloaded archive using the following command.

sudo tar xzf apache-maven-3.8.5-bin.tar.gz
sudo ln -s apache-maven-3.8.5 apache-maven

Step 3 – Configure Maven Environment

You need to set the M2_HOME and MAVEN_HOME environment variables to work with Maven on Debian. Also, set the bin directory to the PATH environment variable. You can set the environments variables by creating new file /etc/profile.d/apache-maven.sh.

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

and add the following content.

export JAVA_HOME=/usr/lib/jvm/java-11-oracle
export M2_HOME=/usr/local/apache-maven
export MAVEN_HOME=/usr/local/apache-maven
export PATH=${M2_HOME}/bin:${PATH}

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

source /etc/profile.d/apache-maven.sh

Step 4 – Verify Installation

You have successfully installed and configured Apache Maven on your Ubuntu system. Use the following command to check the version of Maven.

mvn -version

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/local/apache-maven
Java version: 11.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-oracle
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-46-generic", arch: "amd64", family: "unix"

The Installation of Apache Maven on the Debian system has been completed successfully. You can now remove the downloaded archive file from your system to free space.

rm -f apache-maven-3.8.5-bin.tar.gz

To read more about Apache Maven visit here.

Share.

2 Comments

Leave A Reply

Exit mobile version