Oct 3, 2023 5 min read

2 Ways to Install Apache Maven on Debian 11

Install Apache Maven on Debian 11 with our step-by-step tutorial. Apache Maven is a popular open-source project management tool.

Install Apache Maven on Debian 11
Table of Contents

Introduction

Before we begin talking about how to install Apache Maven on Debian 11, let's briefly understand – What is Maven?

Apache Maven is a popular open-source project management tool. Maven is also referred to as a "build tool," and every build tool facilitates the finishing of a number of projects' source code management-related duties. The Project Object Model (POM) serves as the foundation for Maven's core functionality: The configuration information and other project-related data are contained in a POM file (an XML file). Maven executes a task after retrieving crucial configuration information from a POM file while working on a task.

Additionally, Maven is capable of all the things that a build tool is capable of:  for example, it produces source code, source code documentation, source code compilation, generated source code into JAR files, and packaged code installation on a repository.

Linux is an open-source operating system that is supported by a wide range of distributions, including Debian, Ubuntu, Linux Mint, and others. Among these, Debian is a popular Linux-based operating system distribution that is appropriate for both novice and expert users.

In this tutorial, you will install Apache Maven on Debian 11. We will also address a few FAQs on how to install Apache Maven on Debian 11.

Advantages of Apache Maven

  1. Dependency Management: Apache Maven simplifies managing and resolving project dependencies, ensuring consistent builds and reducing development headaches.
  2. Build Automation: Maven automates the build process, making it easy to compile, test, package, and deploy projects with standardized configurations.
  3. Convention Over Configuration: Maven follows the principle of "convention over configuration," reducing manual configuration and boosting development productivity.
  4. Central Repository: It offers a vast central repository of libraries, allowing developers to easily access and integrate commonly used dependencies into their projects.
  5. Project Lifecycle Management: With Maven, developers gain a comprehensive set of project lifecycle tools, including project initialization, testing, reporting, and release management.

Why Java-based projects should use Apache Maven

As was already mentioned, Maven primarily handles Java-based projects. However, Maven has made a few notable contributions to the management of Java-based projects that have made Maven a practical and helpful tool for Java developers. The following is a list of Maven's significant contributions:

  • Finding the correct JAR files in a version conflict situation is challenging: Maven eliminates version conflicts by ensuring that JAR files are present in the appropriate repositories:
  • Using a central repository accessible at "mvnrepository.com," Maven offers support for accessing JAR files rather than searching for dependencies on many websites.
  • Maven helps create a strong project structure that enables efficient project deployment and execution.

Prerequisites

To install Apache Maven on Debian 11, the following prerequisites must be present on your computer:

  • Most recent Java version
  • Running Debian 11 system

Ways to Install Apache Maven on Debian 11

The procedures and stages listed below were used to install Maven on Debian 11:

  • Using apt
  • Using the official website

Two procedures are available for installing Apache Maven on Debian 11. So, let us discuss each method individually:

Method 1: Installing Apache Maven using apt on Debian 11

Using the apt command, the following procedure installs Apache Maven on Debian 11:

Step 1: Install Java on Debian 11

The most recent version of Maven requires Java to be already installed; if you do not already have it, run the command listed below to install Java on your Debian 11 system:

Note: It is advised that you update the system's repository first by using the command listed below:

sudo apt update

You may now install Java JDK on your Debian 11 system by running the following command:

sudo apt install default-jdk

Check the Java version that is installed to confirm the installation. Execute the following command to accomplish this:

java --version

Step 2: Install Maven

After completing step 1, you can install Apache Maven by running the following command in the Debian 11 terminal:

sudo apt install maven

Method 2: Download and Install Apache Maven on Debian 11

From the official Maven website, you can download and install Apache Maven:

First, run the command listed below to download the ".tar" file:

curl -O https://dlcdn.apache.org/maven/maven-3/3.9.2/binaries/apache-maven-3.9.2-bin.tar.gz

After downloading, run the following command to extract the .tar file:

sudo tar -zxvf apache-maven-3.9.2-bin.tar.gz

After extraction, use the following command to move the files to "/opt/":

sudo mv apache-maven-3.9.2 /opt/maven

How you can set environment variables for Maven on Debian 11

Any program can access information about the installation path of files, temporary file storage, or user profile settings thanks to environment variables: A few Apache Maven environment variables are set here.

Create and modify the "maven.sh" file in the directory "/etc/profile.d/" by using the command below:

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

Write the following lines after opening the "maven.sh" file to set environment variables that will aid in creating a Java environment for Maven and a path to find executable programs:

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

To save the changes and to stop editing, press "Ctrl+S" and "Ctrl+X" respectively:

After making modifications, you must run the "./maven.sh" file to update the shell environment: This command can be used to accomplish your goal:

source /etc/profile.d/maven.sh

How to Remove Apache Maven from Debian 11

If you wish to uninstall Maven from your Debian 11 system, you must run the command listed below:

This command will delete configuration and data files from your Debian 11 system. Additionally, it removes dependencies from your system:

sudo apt autoremove --purge maven

FAQs to Install Apache Maven on Debian 11

How do I check if Maven is already installed on Debian 11? 

Open a terminal and run the command mvn -version. If Maven is installed, it will display the version information; otherwise, an error message will be shown.

How can I install Apache Maven on Debian 11? 

Run the command sudo apt update to update the package index, then sudo apt install maven to install Maven from the Debian repositories.

Which version of Maven will be installed on Debian 11? 

The version available in the default Debian repositories may not always be the latest. It is recommended to check the package version using apt show maven before installation.

Can I install a specific version of Maven on Debian 11? 

Debian's default repositories usually offer the latest stable version. However, if you need a specific version, you can download it from the Apache Maven website and manually install it.

Where can I find the Maven installation directory on Debian 11? 

Maven is typically installed in the /usr/share/maven directory on Debian 11.

How do I set the environment variables for Maven on Debian 11? 

Open the terminal and edit the .profile or .bashrc file in your home directory, adding the line export PATH="/usr/share/maven/bin:$PATH". Save the file and run source ~/.profile or source ~/.bashrc to apply the changes.

Can I use an alternative Maven repository on Debian 11? 

Yes, you can configure alternative repositories in the Maven settings file located at /usr/share/maven/conf/settings.xml or ~/.m2/settings.xml.

Conclusion

As a project management and build automation tool, Apache Maven helps businesses manage Java-based projects successfully. Maven is frequently used in corporate sectors to streamline project development because it helps manage all project stages from building to deployment.

This tutorial has shown you how to install Maven on your Debian 11 system in two different ways. While Method 2 assists in installing it through their official website, Method 1 can be used to install using the apt command.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.