Apache Maven is a very useful open-source project management tool based on POM (project object model). Primarily, it is used to manage Java projects and manage a project’s build, reporting, and documentation. This tutorial show you how to install and configure Apache Maven on Debian 10.
Prerequisites
Before starting installation, ensure that you are logged in as root or user with sudo privileges.
Installing Apache Maven on Debian 10 with apt
The official Debian repositories includes Maven packages and it can be installed with the apt
package manager.
It is very a simple and straightforward process to install Maven on Debian.
At first, update the package index:
sudo apt update
Run the below command install Maven:
sudo apt install maven
Verify the installation by typing:
mvn -version
It will show you something like this:
Maven home: /usr/share/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.19.0-6-amd64", arch: "amd64", family: "unix"
It’s done. Maven is installed on your system, and ready to start using it.
Installing the Latest Release of Apache Maven
Perform the following steps to download and install the latest version of Apache Maven on Debian 10.
1. Install OpenJDK
JDK 1.7 or above need to be installed for Maven 3.3+ version. To install OpenJDK 11, type:
sudo apt update
sudo apt install default-jdk
Verify the installation by running the following command:
java -version
It should show output like below:
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
2. Downloading Apache Maven
Visit the Maven download page to see the latest version of Maven. Currently, at the time of writing this article, the latest version of Apache Maven is 3.6.3
.
We will download the Apache Maven in the /tmp
directory:
wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp
After complete the download, extract the archive in the /opt directory:
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt
To control the Maven versions and updates, create a symbolic link for maven that will point to the Maven installation directory:
sudo ln -s /opt/apache-maven-3.6.3 /opt/maven
To upgrade your Maven installation, unpack the newer version and change the symlink and point to it.
3. Setup environment variables
Now we will set up environment variables, to do so open your text editor and create a new file named mavenenv.sh in the /etc/profile.d/
directory.
sudo nano /etc/profile.d/maven.sh
Put the following following code lines in to it:
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Save and close the file.
We should make this script executable using chmod command:
sudo chmod +x /etc/profile.d/maven.sh
At last, load the environment variables using the source command:
source /etc/profile.d/maven.sh
4. Verify the installation
To verify the installation, use the mvn -version
command to check the Maven version:
mvn -version
It should print like the following:
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_US, platform encoding: UTF-8
OS name: "linux", version: "4.19.0-6-amd64", arch: "amd64", family: "unix"
It’s done. The latest version of Maven is now installed on your Debian system.
Conclusion
You have learned how to install Apache Maven on Debian 10. To learn more about Apache Maven visit the official Apache Maven Documentation page.
If you have any question or feedback, don’t hesitate to leave a comment below.