How To Install Apache Maven on Debian 10 / Debian 9 |

3

Apache Maven is a free build automation tool based on the Project Object Model.

With Maven, you can easily manage a project’s build (used primarily for
Java projects), 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.

This post will help you to install Apache Maven on
Debian 10 &
Debian 9.

Install Java

Apache Maven requires JDK 1.7 or above. Follow the link to install
Oracle JDK on your system.

READ:
How To Install Oracle Java JDK on Debian 10 / Debian 9

OR

If you wish to use OpenJDK for Maven, you can just use the
apt package manager to install the latest version of the OpenJDK package.

sudo apt update

sudo apt install -y default-jdk

Verify the Java installation.

java -version
Output: (Debian 10)


openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Debian-1deb10u1, mixed mode, sharing)

Install Apache Maven

You can visit
Apache Maven’s official website to download the latest stable version of Maven or use the below command to download the Apache Maven v3.6.3 using the terminal

curl -O http://apachemirror.wuchna.com/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Extract the Maven archive using the
tar command.

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

sudo mv apache-maven-3.6.3 /opt/maven

Setup Environment Variables

After you have moved Apache Maven binaries on your system to /opt, set the environment variables by creating a maven.sh file under /etc/profile.d/ directory.

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

Add the following content.

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

Get JAVA_HOME information from the sudo update-java-alternatives -l command

Load the above environment variables in the current shell session using the below command.

source /etc/profile.d/maven.sh

Verify Apache Maven Installation

Check whether the Apache Maven has been successfully configured on your system using the below command.

mvn -version
Output:

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, platform encoding: UTF-8
OS name: "linux", version: "4.19.0-6-cloud-amd64", arch: "amd64", family: "unix"

Conclusion

That’s All. I hope you learned how to install
Apache Maven on
Debian 10 /
Debian 9.