How to Install Apache Maven on Debian 10

Install Apache Maven on Debian 10

In this article, we will have explained the necessary steps to install and set up Apache Maven on Debian 10. 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 software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting, and documentation from a central piece of information. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.

Install Apache Maven on Debian 10

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.

Apache Maven requires JDK. Follow the link to install Oracle JDK on your system:

sudo apt install default-jdk

You can check the default Java by issuing the command below:

java -version

Step 3. Download and Install Apache Maven on the Debian system.

Now we visit Apache Maven’s official website to download the latest stable version of Maven or use the below command:

wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

Then, we will create a symbolic link:

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

Step 4. Configure Maven Environment.

Open your favorite text editor and create a new file named mavenenv.sh in the /etc/profile.d/ directory:

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

Add 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}

Now load the environment variables in the current shell using the following command:

sudo chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh

Step 5. Verify Installation.

You have successfully installed and configured Apache Maven on your Ubuntu system. Use the following command to check the version of Maven:

mvn -version

Output:

Apache Maven 3.6.3 (cecedd343002696d0abmeilana41b8a6ba2883f)
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.23.0-6-amd64", arch: "amd64", family: "unix"

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