Apache Maven is a java based software for project management and comprehension tool developed by Apache Foundation. Based on the concept of a project object model (POM), Maven can manage an entire project’s build. With Maven you can easily store documents, generate reports and documentation from a central piece of information. Installing Maven on Debian 9, is fairly easy task if you follow the steps bellow carefully and should not take more then 10 minutes.
– Consistent usage across all projects
– Simple project setup that follows best practices
– Transitive dependencies
– Ability to Work with multiple projects at the same time
– Ability to write plugins in Java and other languages
– Coherent site of project information
Prerequisites
– Debian 9 VPS
– SSH access to the Debian VPS with root privileges. All our VPS hosting plans come with full root access so you can install anything you want, including Apache Maven
– Java installed on the server
Update the system
First of all, login to your Debian 9 VPS via SSH as user root
ssh root@IP_Address -p Port_Number
You should always update your services, scripts and applications to the latest version, so make sure that all installed packages are up to date
apt update && apt upgrade
Install Maven from repository
Maven can be easily installed from the offcial Debian 9 repositories. To check the version of Apache Maven available in the repositories execute the following command
apt-cache show maven | grep -i version Version: 3.3.9-4
Run the following command to proceed with the installation of Apache Maven version 3.3.9
apt install maven
This will install Apache Maven, Java and all necessary dependencies on your Debian 9 VPS.
Check the installed Maven Version
mvn --version
Output
Apache Maven 3.3.9 Maven home: /usr/share/maven Java version: 1.8.0_171, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre Default locale: en_US, platform encoding: ANSI_X3.4-1968 OS name: "linux", arch: "amd64", family: "unix"
Install and configure Maven from source
If you need a more recent version than the one we installed from the official Debian repositories, we will have to instlal Apache Maven manually from source. If you install Maven from source Java will be not automatically installed. As we previously mentioned, Apache Maven is java based tool Java and the major prerequisite is Java, so we have to run the following commands to install Java to your Debian 9 VPS
apt install default-jdk
Confirm that Java is properly installed
java -version
Output:
openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11) OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Install and configure Maven from source
Now, once we verified the Java is properly installed on the server, we can proceed with the installation of Maven. Download the latest version of Apache Maven directly from the their website. At the moment of writing this article the latest version is 3.5.3.
cd /opt wget http://apache.claz.org/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.zip
Extract the downloaded distribution archive to a directory of your choice. We will extract it to the current working directory
unzip apache-maven-3.5.3
Set the necessary environment variables by creating new file with the following content
nano /etc/profile.d/maven.sh export JAVA_HOME=/usr/lib/jvm/default-java export M2_HOME=/opt/apache-maven-3.5.3 export MAVEN_HOME=/opt/apache-maven-3.5.3 export PATH=${M2_HOME}/bin:${PATH}
Ensure that all paths are properly set, save the file and run the following command to load the environment variables
source /etc/profile.d/maven.sh
Run the following command the check the installed version of Maven
mvn --version
You should get the following output
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T13:49:05-06:00) Maven home: /opt/apache-maven-3.5.3 Java version: 1.8.0_171, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre Default locale: en_US, platform encoding: ANSI_X3.4-1968 OS name: "linux", arch: "amd64", family: "unix"
Depending on your setup, you may need extra configuration. Check out Maven’s official configuration guide for details if necessary.
With this step Apache Maven is successfully installed on your Debian 9 VPS and you can start creating your projects.
If you use one of our Debian Cloud VPS Solutions, you don’t have to Install Apache Maven on Debian 9 yourself, you can simply ask our expert Linux admins to install Apache Maven on your Debian 9 VPS for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on How to Install Apache Maven on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks