Introduction

Apache Maven is a project management tool for developing Java applications.

It resembles other Linux-based project management tools but differs in that it is designed to provide a comprehensive and easy-to-read status of a project. It also incorporates a POM (Project Object Model) approach, meaning that it uses standardized software libraries and plugins.

This guide will walk you through how to install Apache Maven on Debian 9.

installation of apache maven on a server with Debian 9

Prerequisites

  • A system running Debian 9
  • Access to a user account with sudo or root privileges
  • Access to a terminal window/command line (Ctrl-Alt-F2)

Tools/Software

Option 1: Install Apache Maven on Debian with Yum

1. As with most software installations, start by updating the repository index:

sudo apt update

Allow the operation to complete.

2. Install Apache Maven by entering the following:

sudo apt install maven

Allow the installation to complete.

3. Verify the installation by checking the Maven version:

mvn –version

Option 2: Install Latest Version of Apache Maven

Step 1: Install Java Development Kit

Apache Maven requires the Java Development Kit (JDK). This tutorial uses the open-source OpenJDK software package. For compatibility, make sure you are using version 1.7 or higher.

1. In a terminal window, enter the following:

sudo apt install default-jdk

2. Confirm the Java installation and version by entering:

java –version

The first line should return openjdk version “1.8.0_181” or higher.

Step 2: Download Apache Maven For Debian

Note: At the time this article was written, Apache Maven was at version 3.6.0. If you need a more recent version, please see the developer’s download page.

1. Use the wget command to download the files to the /tmp directory:

sudo wget http://ftp.naz.com/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz –P /tmp

Note: If you get an error “command not found,” use the following to install wget:

sudo apt install wget

Once the wget installation finishes, you should be able to download the file.

2. Next, extract the .tar.gz file to the /opt directory: sudo tar xf /tmp/apache-maven-3.6.0-bin.tar.gz –C /opt

Note: If you’re using a different version of Maven, change 3.6.0 to the version you downloaded.

Finally, create a symbolic link to the software location. This helps make typing the location easier for updates and other tasks:

sudo ln –s /opt/apache-maven-3.6.0 /opt/maven

Step 3: Configure Enviroment

Like most Linux software, Apache Maven uses a configuration file. This file is located at /etc/profile.d/maven.sh.

1. Create the file and open it for editing:

sudo nano /etc/profile.d/maven.sh

2. Enter the following lines:

# Apache Maven Environmental Variables

# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2

export JAVA_HOME=/usr/lib/jvm/default-java

export M2_HOME=/opt/maven

export MAVEN_HOME=/opt/maven

export PATH=${M2_HOME}/bin:${PATH}

Save the file and exit.

3. Next, change permissions by entering the following:

sudo chmod +x /etc/profile.d/maven.sh

4. Then load the file by entering:

Source /etc/profile.d/maven.sh

Step 4: Verify Apache Maven Installation

Enter the following:

mvn –version

The system should display your Apache Maven version, the location of Maven Home, and your Java version.

Conclusion

You should now have successfully installed Apache Maven on your Debian 9 server.

For more information or beginner and intermediate tutorials, please see the offical maven documentation.