Quantcast

How to Install Apache Maven on Ubuntu 22.04 LTS

Apache Maven is an open-source tool that allows the building automation of your java projects. It can also be used for projects in C#, Ruby, etc. Its most famous usage would likely involve Java development! The maven project comes from the Apache Software Foundation, where they were previously part of the Jakarta Project before moving on their own.

In the following tutorial, you will learn how to install Apache Maven on Ubuntu 22.04 LTS Jammy Jellyfish using APT or downloading the archive and manually to install Maven using the command line terminal.

Update Ubuntu

Before you begin, make sure your system is up-to-date using the following command.

sudo apt update && sudo apt upgrade -y

Install Apache Maven – APT Method

Ubuntu features Apache Maven in its default repository, making the installation straightforward. Still, the repository version is often lagging behind the latest, so maybe not be as desirable as downloading the latest archive and installing manually.

Use the following command to begin the installation.

sudo apt install maven -y

Confirm the installation and the version installed on your system using the following version command.

mvn -version

Example output:

How to Install Apache Maven on Ubuntu 22.04 LTS

For users who prefer using the latest version of Maven, if the repository version is out of date for your needs, or if you need the newer version for better features, look to the next section.

Install Apache Maven – Manual Method

The second option is to download and install the latest version manually, which is better suited for more experienced users.

Install Default JDK (Java)

First, before you install Apache, you must install Java on Ubuntu using the following command.

sudo apt install default-jdk -y

Download & Setup

Next, use the wget command to download the archive. To find the latest version, visit here.

Example:

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

Next, extract the archive folder to the /opt/ directory.

sudo tar xzf apache-maven-3.8.4-bin.tar.gz -C /opt/

Now, navigate to the directory.

cd /opt/

Given that you have extracted the directory to the /opt/ location, you can either rename the folder or symlink it. Often, the symlink is the recommended method.

sudo ln -s apache-maven-3.8.4 maven

Install Apache Maven Environment

The environment variables need to be set, and this can be done by creating maven.sh under the /etc/profile.d/ directory.

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

Next, add the following to the file.

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Example:

How to Install Apache Maven on Ubuntu 22.04 LTS

Save the file and then exit by pressing CTRL+O, then CTRL+X.

The last task is now to enable the environment with the following command.

source /etc/profile.d/maven.sh

Confirm the installation by running the following command.

mvn -version

Example output:

How to Install Apache Maven on Ubuntu 22.04 LTS

Comments and Conclusion

In the tutorial, you have learned two methods to install Apache Maven on Ubuntu 22.04 LTS.

Overall, Maven is a great build tool that automates the whole process of building your project as per your requirements. It makes it easy for you to start your project in different environments without handling dependencies injection, builds or processing, etc., by adding new dependencies with some lines of commands only.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!