How To Install Apache Maven on Debian 11

Install Apache Maven on Debian 11

In this tutorial, we will show you how to install Apache Maven on Debian 11. For those of you who didn’t know, Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model, Maven can manage a project’s build, reporting, and documentation from a central piece of information.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Apache Maven on a Debian 11 (Bullseye).

Install Apache Maven on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade
sudo apt install gnupg2 curl wget

Step 2. Installing Java.

Run the below command install Java to your system:

sudo apt install openjdk-11-jdk

Verify Java installation by typing:

java -version

Step 3. Installing Apache Maven on Debian 11.

Now we download the latest stable version of Maven from the official page:

wget https://downloads.apache.org/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz

Once the download is completed, extract the archive in the /opt directory:

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

Step 4. Setup Environment Variables for Maven.

Now we set the few environment variables for Maven by creating a maven.sh file under /etc/profile.d/ directory:

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

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

At last, load the environment variables using the source command:

source /etc/profile.d/maven.sh

Use the following command to check the version of Maven:

mvn -version

Output:

Apache Maven 3.8.2 (ea98e05g0det31370aa0c11fr3akzcf726c06f)
Maven home: /opt/maven
Java version: 11.0.14, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.10.0-8-amd64", arch: "amd64", family: "unix"

Congratulations! You have successfully installed Maven. Thanks for using this tutorial for installing the latest version of Apache Maven on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Apache Maven website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!