How to Install Apache Maven on Debian 10

Published on

4 min read

Install Apache Maven on Debian 10

Apache Maven is an open-source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM), which is essentially an XML file containing information about the project, configuration details, the project’s dependencies, and so on.

This article shows two ways to install Apache Maven on Debian 10.

The standard Debian repositories contain Maven packages that can be installed with the apt package manager. This is the easiest way to install Maven on Debian. However, the version included in the repositories may lag behind the latest version of Maven. To install the latest version of Maven, follow the instructions provided in the second part of this article.

Choose the installation method that is most appropriate for your setup and environment.


The instructions assume that you are logged in as root or user with sudo privileges .

Installing Apache Maven on Debian with apt

Installing Maven on Debian using apt is a simple, straightforward process.

  1. Update the package index and install Maven by running the following commands:

    sudo apt updatesudo apt install maven
  2. Run the mvn -version command to verify the installation:

    mvn -version

    The output should look something like this:

    Maven home: /usr/share/maven
    Java version: 11.0.6, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "4.19.0-6-amd64", arch: "amd64", family: "unix"

That’s it. Maven has been installed on your Debian system, and you can start using it.

Installing the Latest Release of Apache Maven

In this section, we’ll provide a step by step instructions about how to install the latest Apache Maven version on Debian 10.

1. Install OpenJDK

Maven 3.3+ requires JDK 1.7 or above to be installed on your system.

Install OpenJDK 11 , by typing:

sudo apt updatesudo apt install default-jdk

Verify that Java was successfully installed by checking its version:

java -version

The output should look something like this:

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

2. Download Apache Maven

At the time of writing this article, the latest version of Apache Maven is 3.6.3. Before continuing with the next step, check the Maven download page to see if a newer version is available.

Use wget to download the Apache Maven archive in the /tmp directory:

wget -P /tmp

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

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

To have more control over Maven versions and updates, we will create a symbolic link maven that will point to the Maven installation directory:

sudo ln -s /opt/apache-maven-3.6.3 /opt/maven

Later, to upgrade your Maven installation, simply unpack the newer version and change the symlink to point to the latest version.

3. Setup environment variables

Next, we’ll need to set up the environment variables . To do so, open your text editor and create a new file named in the /etc/profile.d/ directory.

sudo nano /etc/profile.d/

Paste the following lines:

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 and close the file. The script will be sourced at shell startup.

Make the script executable by typing the following chmod command:

sudo chmod +x /etc/profile.d/

Load the environment variables in the current session using the source command:

source /etc/profile.d/

4. Verify the installation

To validate that Maven is installed properly use the mvn -version command which will print the Maven version:

mvn -version

You should see something like the following:

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

That’s it. The latest version of Maven is now installed on your Debian system.


We have shown you how to install Apache Maven on Debian 10. You can now visit the official Apache Maven Documentation page and learn how to get started with Maven.

If you hit a problem or have feedback, leave a comment below.