Categories: UbuntuUbuntu Feed

How to Install Apache Maven on Ubuntu 22.04

Apache Maven is developed for the building the Java-based applications. It can also build applications written in C#, Ruby, Scala, and other languages. Maven is very helpful for starting new build applications in various environments. It can manage a project’s build, reporting, and documentation from a central piece of information.

Maven maintains its own repository https://mvnrepository.com/ containing a large number of user libraries and still growing. That helps applications fulfill the dependencies during the build. In most situations, Maven nullifies the version conflict by locating the correct Jar files.

In this tutorial, we will show 2 methods to install and configure Apache Maven on Ubuntu 22.04 Linux system. This article will also apply to other Ubuntu, Debian, and Linux Mint systems.

Sponsored
class="heading1">Installing Java

Apache Maven can be configured on any system that has Java installed. The latest Maven version required JDK 1.7 or newer versions. On Ubuntu, you can run the following command to install JDK 11:

sudo apt update 
sudo apt install default-jdk 

Once the Java is installed, check the current default set Java version:

java -version 
Output:
openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Method 1: Installing Maven Using Apt

We can quickly install the Apache Maven using the Apt package manager. Open a terminal and execute following command:

sudo apt install maven 
Installing maven on ubuntu

You will notice that the old version of Apache Maven was installed from the Apt repository. The second method will help you to install the latest Maven version on the Ubuntu system.

Method 2: Installing Latest Maven From Source Code

Follow the below instructions to install Latest Maven version on Ubuntu systems:

  1. You can download Apache maven from its official website or use following command to download Apache Maven 3.8.5 on your system.
    wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz 
    
  2. Now extract the downloaded Maven archive file using the following command.
    sudo tar xzf apache-maven-3.8.5-bin.tar.gz -C /opt 
    sudo ln -s /opt/apache-maven-3.8.5 /opt/maven 
    

    The above commands will extract Maven under /opt directory and create a symbolic link /opt/maven to that directory.

    Sponsored
  3. As you have downloaded pre-compiled Apache Maven files on your system. Now set the environments variables by creating new file /etc/profile.d/maven.sh.
    sudo vi /etc/profile.d/maven.sh 
    

    Add below content to the file:

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

    Save your file and close it.

  4. Next load the environment variables in the current shell using the following command.
    source /etc/profile.d/maven.sh 
    

    During the next system reboot, the environment will automatically load.

  5. You have successfully installed and configured Apache Maven on your Ubuntu system. You can check the installed Maven version with the following command:
    mvn -version 
    
    Check maven version
  6. Finally, clean up the disk by removing the downloaded archive file.
    rm -f apache-maven-3.8.5-bin.tar.gz 
    

Uninstall (Remove) Apache Maven

If the Apache Maven is no longer required, you can uninstall it from your system.

Use the following command to uninstall maven using Apt package manager.

sudo apt remove --purge maven 

If you have installed maven from the source code, use the following commands to remove it.

sudo unlink /opt/maven 
sudo rm -rf /opt/apache-maven-3.8.5 

Conclusion

In this tutorial, You have learned about the installation of Apache Maven on the Ubuntu system.

The post How to Install Apache Maven on Ubuntu 22.04 appeared first on TecAdmin.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

4 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

5 days ago