How To Set up Apache Maven on Debian 11

In this guide from the Linux Tutorials, we intend to teach you How To Set up Apache Maven on Debian 11.

Maven is a popular open-source build tool developed by the Apache Group to build, publish, and deploy several projects at once for better project management. The tool provides allows developers to build and document the lifecycle framework.

Maven is written in Java and is used to build projects written in C#, Scala, Ruby, etc. Based on the Project Object Model (POM), this tool has made the lives of Java developers easier while developing reports, checking builds, and testing automation setups.

How To Set up Apache Maven on Debian 11

To set up Apache Maven, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Debian 11.

Install Apache Maven on Debian 11

First, update your APT repository with the command below:

sudo apt update

To install the latest Apache Maven on your server, you need to have Java installed on your server.

To install Java on Debian 11, run the command below:

sudo apt install default-jdk -y

Next, you need to visit the Maven Downloads page and copy the link address of the binary tar.gz package of Apache Maven.

Then, use the wget command to download it on your server:


Extract your downloaded file to the opt directory with the command below:

sudo tar xzf apache-maven-3.8.5-bin.tar.gz -C /opt/

At this point, switch to your opt directory:

cd /opt/

Also, you can either rename the folder or symlink it. Often, the symlink is the recommended method.

sudo ln -s apache-maven-3.8.5 maven

Here you need to install Apache Maven environments. To do this, you can create under the /etc/profile.d directory:

sudo vi /etc/profile.d/

Add the following content to the file:

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

When you are done, save and close the file.

Next, enable your Apache Maven environment on Debian 11 with the following command:

source /etc/profile.d/

You can verify your Apache Maven installation on Debian 11 by checking its version:

mvn -version

In your output you will see:

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/maven
Java version: 11.0.15, 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"


Maven is a great build tool that automates the whole process of building your project as per your requirements. It makes it easy for you to start your project in different environments without handling dependencies injection, builds or processing, etc., by adding new dependencies with some lines of commands only.

At this point, you learn to Set up Apache Maven on Debian 11.

Hope you enjoy it.

You may be interested in these articles:

How To Install Java on Debian 11

How To Set up Ruby on Rails on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!