How To Install Apache Maven on Ubuntu 22.04

In this tutorial, we want to teach you to Install Apache Maven on Ubuntu 22.04.

Apache Maven is a powerful build tool primarily for Java software projects. It is implemented in Java which makes it platform-independent.

Build tools perform the compilation, testing, packaging, and deployment of the final product. The advantage of performing these steps automatically instead of a human performing these steps is that the build is reproducible, faster, and less error-prone.

Maven can also perform related activities, e.g., create websites, upload build results or generate reports.

Maven also supports the creation of the initial folder structure for applications to make it easy to get started.

Install Apache Maven on Ubuntu 22.04

To install Apache Maven, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Ubuntu 22.04.

Now follow the steps below to install the latest release of Maven on Ubuntu 22.04.

Install OpenJDK on Ubuntu 22.04

To set up Apache Maven, you need to have Java installed on your server. The default version of Java available in Ubuntu 22.04 is OpeJDK-11 which is compatible with Apache Maven’s latest version.

First, update your local package index with the command below:

sudo apt update

Then, run the following command to install the OpenJDK:

sudo apt install default-jdk

Verify your Java installation by checking its version:

java --version
Output
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

Install Apache Maven LTS on Ubuntu 22.04

At this point, you need to visit the Apache Maven Downloads page and get the latest version available there by using the wget command.

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

When your download is completed, extract your downloaded file with the following command:

tar -xvf apache-maven-*-bin.tar.gz

Then, move your extracted file to the /usr/share directory with the command below:

sudo mv apache-maven-3.8.5 /usr/share/maven

To use the maven command tool from anywhere in your terminal, you need to add its folder path in your bash profile. You can use the commands below:

# echo 'export PATH="$PATH:/usr/share/maven"' >> ~/.bashrc
# echo 'export PATH="$PATH:/usr/share/maven/bin"' >> ~/.bashrc

At this point, you need to source your bash profile:

source ~/.bashrc

Check your Maven installation on Ubuntu 22.04 by checking the MVN version:

mvn -v
Output
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/share/maven
Java version: 11.0.15, vendor: Private Build, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.17.5-051705-generic", arch: "amd64", family: "unix"

Remove Apache Maven

If you no longer want to use maven, use the command below to uninstall it from Ubuntu 22.04:

sudo rm /usr/share/maven

To remove Java, you can use:

sudo apt autoremove default-jdk --purge

Conclusion

At this point, you learn to Install Apache Maven on Ubuntu 22.04.

Hope you enjoy it.

You may be like these articles:

Set up Apache Maven on AlmaLinux 8

How To Set up Apache Maven on Centos 7

How To Set up Apache Maven on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay informed and not overwhelmed, subscribe now!