DebianDebian Based

How To Install Apache Maven on Debian 12

Install Apache Maven on Debian 12

In this tutorial, we will show you how to install Apache Maven on Debian 12. Apache Maven is an essential tool for Java developers, providing a robust and efficient way to manage project dependencies, build, and deploy applications.

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 the step-by-step installation of the Apache Maven on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Apache Maven.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Apache Maven on Debian 12 Bookworm

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

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing OpenJDK.

Maven relies on Java, so you need to have Java Development Kit (JDK) installed. Let’s install the last OpenJDK versions using the following command below:

sudo apt install openjdk-11-jdk

Step 3. Installing Apache Maven on Debian 12.

First, we download the latest version of Maven from the official website using the following command:


With the Maven archive downloaded, it’s time to extract its contents and prepare them for use:

sudo mkdir /opt/maven
sudo tar -xf apache-maven-3.9.4-bin.tar.gz -C /opt/maven

This extracts the contents of the archive to /opt/maven, making Maven accessible system-wide.

To ensure that Maven can be executed from any location on your system, you need to set up environment variables:

sudo nano /etc/environment

Add the following lines to set Maven environment variables:


Reload the environment variables to apply the changes:

source /etc/environment

To confirm that Maven is successfully installed and configured, run the following command:

mvn -version


Apache Maven 3.9.4
Maven home: /opt/maven/apache-maven-3.x.x

Step 4. Troubleshooting.

If you encounter any issues during the installation process, here are some common problems and their solutions:

  • Problem 1: Unable to Update System Packages

If you face difficulties updating system packages, ensure that your internet connection is stable. If the issue persists, consult Debian’s official documentation for package management troubleshooting.

  • Problem 2: Java Installation Fails

Double-check the OpenJDK version you’re trying to install. Ensure that your Debian 12 system is up-to-date, and try the installation again.

  • Problem 3: Maven Version Incompatibility

If you encounter version compatibility issues, consider installing a different version of Maven that suits your project’s requirements. You can find various versions on the official Apache Maven website.

Congratulations! You have successfully installed Apache Maven. Thanks for using this tutorial to install the latest version of the Apache Maven on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Apache 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!
Back to top button