How to Install Apache Maven on Debian 11

Install Apache Maven on Debian 11

In this article, we will have explained the necessary steps to install Apache Maven on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Apache Maven is a command-line tool written in Java for building Java applications and JVM (Java virtual machine). It is based on the conception of a project object model and is used in particular for the deployment of Java-based projects. Apache Maven facilitates the daily work of Java developers and generally helps to understand a Java-based project.

Install Apache Maven on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade

Step 2. Install Java.

Install OpenJDK 11, because Apache Maven requires Java 1.8 or greater:

sudo apt install -y openjdk-11-jdk

Verify the default Java installation by issuing the command below:

java -version

Step 3. Install Apache Maven on Debian Bullseye system.

Now run the command below to grab Maven from its official website:

curl -O

Once the download is completed, extract the downloaded file with the following command:

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

After that, you will need to set up the environment variables for Java and Maven. You can do this by creating file:

sudo nano /etc/profile.d/

Add the next variables with the values:

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

Finally, load the environment variables by running the following command:

source /etc/profile.d/

Verify Maven installation:

mvn -version

You should see the following output:

Apache Maven 3.8.2 (97c98gamafdfee7767ce5ffb20218da4f719f3; 2021-10-24T18:46:37Z)
Maven home: /opt/maven
Java version: 11.0.12, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-20-generic", arch: "amd64", family: "unix"

That’s all you need to do to install Apache Maven on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Apache Maven on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.