How To Install Apache Maven on Ubuntu 20.04

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

Apache Maven is a cornerstone of Java development and the most used build management tool for Java. Maven’s streamlined, XML-based configuration model enables developers to rapidly describe or grasp the outlines of any Java-based project, which makes starting and sharing new projects a snap. Maven also supports test-driven development, and long-term project maintenance, and its declarative configuration and wide range of plugins make it a popular option for CI/CD.

Steps To Install Apache Maven on Ubuntu 20.04

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

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

Install OpenJDK on Ubuntu 20.04

To set up Apache Maven, you need to have Java installed on your server. The default version of Java available in Ubuntu 20.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 -y

Verify your Java installation by checking its version:

java --version
Output
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu120.04.1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu120.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.

sudo wget https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-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.9.0 /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 20.04 by checking the MVN version:

mvn -v
Output
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: /usr/share/maven
Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-29-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 20.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 20.04.

Hope you enjoy it. You may be like these articles on the Orcacore website:

How To Install OpenSSL 3 on Ubuntu 20.04

Install and Configure Jekyll on Ubuntu 20.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!