Install Apache Maven on Ubuntu 20.04 - Step by Step process ?

Apache Maven is an open-source and free project management utility that is used for building and managing projects written in various languages. 

It is particularly used for the deployment of Java-based applications. It helps you to get all the necessary libraries that you need to build your application. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Apache queries.

In this context, we shall look into how to install Apache Maven on the Ubuntu OS.


How to install Apache Maven on the Ubuntu system ?

Here, we will look into the following methods to install Apache Maven:

a. Installing Apache Maven via apt

b. Installing Apache Maven via .deb package


Also, You must have sudo access to install / remove the Apache Maven on your system.


a. How to install Apache Maven via apt on Ubuntu ?

Here, we are going to install Apache Maven via apt:


1. Update system's repository index using the command below in Terminal:

$ sudo apt-get update

Enter the password for sudo.

2. Then use the following command in order to install Apache Maven:

$ sudo apt-get install maven

Now you might be provided with the Y/n option, press Y to carry on the installation of Apache Maven. Then the installation will be started on your system.

3. Once the installation is completed, you can verify it by using the command below in Terminal:

$ mvn -version

This command will display the version of Apache Maven installed.

Now Apache Maven has been successfully installed and is ready to use.


b. How to install Apache Maven from the official website on Ubuntu ?

Here, we are going to download and install Apache Maven from its official website:


1. Before installing Apache Maven, first you will need to install JDK. 

To install JDK, update the system repository index using the below command:

$ sudo apt update

Then install JDK as follows:

$ sudo apt install default-jdk

2. To verify if JDK has been installed, issue the below command in Terminal:

$ java --version

The output will verify that JDK has been successfully installed on your system.

3. Now, you will need to download the Apache Maven from its official website . Run the command below in Terminal to download the most recent release:

$ wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

This command will save the downloaded Apache Maven archive file apache-maven-3.6.3-bin.tar.gz in the /tmp directory.

4. Now, extract the archive using the below command in Terminal:

$ tar -xvzf apache-maven-3.6.3-bin.tar.gz

This command will extract the file to the apache-maven-3.6.3 directory.

5. Now, copy the extracted directory apache-maven-3.6.3 to /opt/ as follows:

$ cp -r apache-maven-3.6.0 /opt/maven

6. Now, you will need to setup the environment variables.

To do this, create a script file maven.sh in the /etc/profile.d directory using the below command in Terminal:

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

Add the below lines in the script:

export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Now you can save and exit this script.

7. Now use the below command to give the script executable permissions:

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

8. Load the environment variables using the below command:

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

Now the installation of Apache Maven has been completed. 

You can verify it by running the below command in Terminal:

$ mvn -version

After running the above command, you will receive an output which verifies that Maven version 3.6.3 has been successfully installed.


How to Uninstall Apache Maven from Ubuntu ?

In case you no longer need Maven on your system, you can easily uninstall it using the below command in Terminal:

$ sudo apt-get remove maven


[Need to install Apache Maven from your Debian Linux System ? We are available. ]

This article covers methods to easily install Apache Maven on the Ubuntu system. You will also learn how to uninstall Apache Maven from Ubuntu if you ever need to do so.

Apache Maven is a free and open-source project management tool primarily for Java projects. It is based on POM and also used to build and manage projects written in C#, Ruby, Scala, and others.


To Install Apache Maven on Ubuntu:

1. Apache Maven is based on Java. So Java must be installed in your server. You can install the Java using the following command:

$ apt-get install default-jdk -y

2. By default, Apache Maven is available in the Ubuntu 20.04 default repository. You can install it with the following command:

$ apt-get install maven -y

3. Once the installation is completed, you can verify the Apache Maven version with the following command:

$ mvn -version

Related Posts