How to install Apache Maven on Debian 10?

0
108

In this post, we will show you how to install Apache Maven on Debian 10.

To manage projects done in Java, there is no better tool than Apache Maven. This fantastic tool, belonging to the Apache foundation, comes with predefined objectives to perform certain clearly defined tasks, such as code compilation and packaging.

There are many features that make Maven a great tool. However, the key is that Maven is ready for network use. In addition, its functions are made extensible by the ability to install plugins. Finally, Maven relies on the Project Object Model (POM) to describe the project, as well as its dependencies for later deployment.

If you want to learn how to install Apache Maven on Ubuntu 18.04 or Debian 9, you can read our tutorial:

How to install Apache Maven on Ubuntu 18.04 / Debian 9?

So, let’s start to install Apache Maven.

Installing Apache Maven on Debian 10

Before starting it is advisable to make an update to the whole system. To do this, open a terminal session and run the following:

:~$ sudo apt update && sudo apt upgrade

In case your Debian system does not have sudo active, you can learn how to activate it with the following post:

How to enable sudo in Debian 10?

Now with the updated system you will have at your disposal the last patches to be guaranteed and thus you will have a more stable system.

Install Java on Debian 10

Apache Mave is built in JAva, so it requires it to be installed on the system. You can choose between the proprietary version of Oracle or OpenJDK that comes in the Debian repositories. We will use this last option.

:~$ sudo apt install openjdk-11-jre openjdk-11-jdk
1.- Installing Java on Debian 10
1.- Installing Java on Debian 10

After finishing the installation, we check that everything is OK showing the installed version of Java.

:~$ java --version
2.- Java version
2.- Java version

So, everything’s right for now.

Install Maven. Method 1: Using the official repositories

Apache Maven is included in the official Debian 10 Buster repositories. However, this version is not the latest available. Then, we will not be able to get the latest application updates.

So to install it, on the terminal, run the following:

:~$ sudo apt install maven

That is it. It is the easiest method but we will always be outdated and it is not convenient. So I will show you a way to install the latest version available.

Method 2: Download it and install it

The second method is a little more complicated but not so much. In this method, we will download the binary from the Apache servers and install it normally.

This method ensures that you always download the latest version available at any time. So let’s go for it.

Navigate to the tmp folder and download alli Apache Maven.

:~$ cd /tmp/
:~$ wget -c https://www-us.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
3.- Download and install Apache Maven on Debian 10
3.- Download and install Apache Maven on Debian 10

Then unzip the file and move it to /opt/.

:~$ tar -zxvf apache-maven-3.6.2-bin.tar.gz
:~$ sudo mv apache-maven-3.6.2 /opt/maven

Apache Maven works with Java environment paths and variables. Then you have to define them before using it. To do this, create a file called maven.sh in /etc/profile.d/ and add the following:

:~$ sudo nano /etc/profile.d/maven.sh
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
4.- Configuring Apache Maven for the first use
4.- Configuring Apache Maven for the first use

To apply the changes, just use the following command:

:~$ source /etc/profile.d/maven.sh

Finally, you will be able to show the installed version of Maven.

:~$ mvn -version
5.- Apache Maven on Debian 10
5.- Apache Maven on Debian 10

This indicates that Maven is ready for work.

Conclusion

Apache Maven is a fantastic tool for Java projects. These projects that every day continue to be references in many companies. So learning how to install Apache Maven on Debian 10 could be quite useful.

LEAVE A REPLY

Please enter your comment!
Please enter your name here