| by Arround The Web | No comments

How to Install Apache Maven on Linux Mint 21

Apache Maven is a popular, open-source project management tool used to develop and manage Java projects and documentation. It comes from the concept of POM (project object model) with the extensible feature. It has the ability to add plugins and support other languages as well, such as C#, Scala, and Ruby. It is a helpful comprehension tool that gives bundles of details about projects. This tool is also available for Linux distribution also and in this tutorial, we will learn how to install it on Linux Mint 21 system.

Install Apache Maven on Linux Mint 21

We have two approaches to installing Apache Maven on Linux Mint 21 system:

  1. Through APT
  2. Through Source Code

Method 1: Install Apache Maven through APT

The Installation process of Apache Maven using apt is quite straight away; there is no hurdle in it. But make sure your system is updated.

Run the following command to let the system refreshed with up-to-date packages:

$ sudo apt update

After updating the packages list, now you can directly install Apache Maven from system’s default repository with the help of the following command:

$ sudo apt install maven

Check its version to confirm the successful installation through the given command:

$ mvn --version

Method 2: Install Apache Maven through Source Code

This method will surely install the latest update of Apache Maven on the Linux Mint 21 system. For this, follow the below-given step-by-step instructions carefully:

Step 1: Running the command mentioned below to ensure that system is up-to-date and all packages are updated:

$ sudo apt update

Step 2: In the next move, we need to download JDK as it is the prerequisite of Apache Maven. We can do it through the below-given command:

$ sudo apt install default-jdk

Step 3: Confirm the Java installation using the version command:

$ java -version

Step 4: To retrieve the source package of Apache Maven from its official website, execute the following command:

$ wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

You can also directly copy the link from the official source to download the source file through wget command on your system:

Step 5: Move the downloaded Apache Maven source package to the /tmp file through following command:

$ mv /home/wardah/apache-maven-3.8.6-bin.tar.gz /tmp

Step 6: Extract the downloaded Apache Maven source package in the /tmp file by making use of following command in terminal:

$ sudo tar -xvzf /tmp/apache-maven-3.8.6-bin.tar.gz

Step 7: Once all files are extracted, copy them into the opt/maven directory using the command:

$ sudo cp -r apache-maven-3.8.6 /opt/maven

Step 8: To setup the environment for Apache Maven, open maven.sh file with the nano editor:

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

In this file, put the following lines of code:

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 the file by pressing Ctrl+O you save the file.

Step 9: Make the file executable from the following command:

$ sudo chmod +x /etc/profile.d/maven.sh

Step 10: The last step to set the environment for Maven using the source command that is used to lload the source variables:

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

Step 11: After successfully running all the above steps, now you can check the version of Apache Maven that is installed on Linux Mint 21 system:

$ mvn -version

How to Remove Apache Maven from Linux Mint 21

You can also remove Maven from the Linux Mint 21 system by executing the following command:$

sudo apt remove maven


Apache Maven is an open source and helpful Java project management tool that is used to create different projects in Java and other scripting languages. We have provided multiple ways to install Apache Maven on a Linux system. The first one installs an older version of Apache Maven while the second method installs the latest version on your Linux system.

Share Button

Source: linuxhint.com

Leave a Reply