How to Install Apache Maven on Debian 11

0

Apache Maven is an open-source software project management and comprehension tool used by Java developers worldwide to manage all stages of the software development lifecycle, from building, reporting, assembling, and deployment.

You can also use Maven to build and manage projects written in C#, Ruby, Scala, and other languages.

Here, we will see how to install Apache Maven on Debian 11.

Install Java on Debian

Apache Maven requires JDK 7 or above. You can either install Oracle Java or OpenJDK for your Maven installation.

READ: How To Install Java on Debian 11

OR

Here, I will be using OpenJDK v11 for Maven installation.

sudo apt update

sudo apt install -y openjdk-11-jdk

Once you installed Java, verify the Java installation by running the below command.

java -version

Output:

openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, mixed mode, sharing)

Install Apache Maven on Debian

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.8.2 using the terminal.

curl -O https://downloads.apache.org/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz

Extract the Maven archive using the tar command and move the files to the /opt/ directory.

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

sudo mv apache-maven-3.8.2 /opt/maven

Setup Environment Variables for Maven

After you have placed Apache Maven binaries into the /opt directory, set the few environment variables for Maven by creating a maven.sh file under /etc/profile.d/ directory.

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

Add the following variables with the values.

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.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /opt/maven
Java version: 11.0.12, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.10.0-8-amd64", arch: "amd64", family: "unix"

Conclusion

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

You might also like