How to Install Apache Maven on Ubuntu 20.04 / 22.04 Server

How to Install Apache Maven on Ubuntu 20.04 / 22.04 Server. If you have to choose one software management and build an automation tool for a Java based project, it would be Apache Maven.

Apache Maven is a software project management and comprehension tool. It was created by the Apache Software Foundation (ASF) to ease the build process of software projects written in Java. Also provides a library management system for the JVM, integration with issue tracking systems, and both interactive and non interactive reporting.

In addition, it is an open source tool for managing Java based projects. Foremost, Apache Maven manages the complete life cycle of Java based projects from building to deployment.

Moreover, it is also a build automation tool that handles the building, testing and reporting of a project’s code. So, Maven provides the means to manage a project’s build, reporting and documentation from a central piece of information.

In this article, we go through the basic introduction of Apache Maven, its features and advantages. Next we move onto how to install them on Ubuntu with the default repository or use manual installation to avail of the latest version.

What is Apache Maven

First of all, Apache Maven is a build automation tool used to manage Java projects. It is used to create, run and test projects and generate reports and documentation.

It executes the process of software development. Apache Maven uses a project object model (POM), which defines the project, its components and their relationships. 

Additionally, it uses POM to describe a project’s build, reporting and documentation needs. The POM describes the project, its packaging and the dependencies it has on other external libraries or applications. This makes it possible for developers to build an application once but run it on any server as long as they have Maven installed on their machine.

Maven is designed to be a universal build tool. Used as a build tool in any situation where there is a need to manage the complexity of large projects.

Apache Maven has many features that make it the best software build tool among most Java developers. Basically, it provides a uniform build system for all Java applications, allows developers to use their preferred IDE, supports dependency management, and much more.

As a project management tool, it defines goals, dependencies, and reporting. As a comprehension tool, it understands your project’s structure and builds files. Maven is an alternative to tools like ANT or Rake.

Besides, it builds projects in which multiple software modules are compiled and linked to create executable programs. Apache Maven uses conventions for project organization and naming so that a developer easily handles any project.

Certainly, Maven makes your life easier by automating your tasks (building, testing, and documentation). It also allow you to customize these tasks.

It’s used by thousands of developers around the world every day because it helps them do their jobs better.

Feature of Apache Maven

Some of the Maven features are as follows:

  • Simple project setup based on best practices.
  • Consistent application across all projects.
  • Capable of working on numerous projects at the same time.
  • It has a big and expanding library and metadata collection.
  • With little or no additional setup, you may have immediate access to new functionality.
  • Ant tasks for managing dependencies and deploying outside of Maven.
  • Model based constructions.
  • Coherent site of project information.
  • Release management and distribution publication
  • Dependency management.

Advantages of Apache Maven

Here are some of the advantages offered by Apache Maven.

  • Aids in the administration of all project management procedures such as construction, documenting, releasing, and distribution.
  • Simplifies the project building process.
  • Improves project and construction process performance.
  • The downloading of Jar files and other dependencies are handled automatically.
  • All necessary information is easily accessible.
  • Allows the developer to construct a project in several contexts without having to worry about dependencies, procedures, and so on.
  • It is simple to add new dependencies in Maven by adding the dependent code in the pom file.

Follow this post to learn how to install Apache Maven on the Ubuntu 20.04 or 22.04 server.

How to Install Apache Maven on Ubuntu 20.04 / 22.04 Server


Here are the few things you will need for this tutorial:

  • A server running Ubuntu 22.04, 20.04.
  • SSH access to the server (or, if you’re on a desktop, simply open Terminal).
  • A user with sudo or root access.

Method 1: Install Apache Maven on Ubuntu Using apt Repository

Maven packages are available in the official Ubuntu repository and you install them using the apt package manager. 

Update System Repositories

Run the following command in the terminal to ensure that all of your system packages are up to date.

					sudo apt update

Install Apache Maven on Ubuntu With apt Command

You can install the Apache Maven using the following apt command in the terminal.

					sudo apt install maven

Press y on the prompt and wait for the installation to finish.

Verify Maven Installation and Check Maven Version

You can check the Maven version with the following command. This will also verify the Maven installation on Ubuntu.

					mvn -version

This method for installing Maven on Ubuntu is the simplest. However, the version in the repositories may be older than the most recent version of Maven.

Method 2: Manual Installation of Apache Maven on Ubuntu 20.04/22.04

The manual approach of installing Apache Maven provide you with the latest version. Manually installing Maven allows you to obtain and install the most recent version.

Install JAVA/OpenJDK

First and foremost, ensure the Java installation on your Ubuntu server; if it is not, use the following command to install it:

					sudo apt install default-jdk -y

Download Apache Maven From the Official Repository/Website

You can use the following wget command to get the most recent version of Apache Maven from their official website.

					wget -P /tmp

Extract the Downloaded Maven Package in Separate Directory

Run the following cd command to create and navigate to a new directory called tmp

					cd /tmp

Next, extract the Apache Maven package you downloaded earlier using the following command.

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

Once the extraction is completed, copy the contents of the extracted folder into a new directory called opt with the following command.

					sudo cp -r apache-maven-3.6.3 /opt/maven

Set up environment variables

Next, you have to configure the environment variables by creating a Maven script file called in the /etc.profile.d directory using the following command.

					sudo nano /etc/profile.d/

Paste the following code into the opened file.

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

Press CTRL+O and CTRL+Z to save and exit the file.

Enable the Executable Permission for the Apache Maven Script

Type the following command to make the newly generated Apache Maven script executable:

					sudo chmod +x /etc/profile.d/

Load the Environment Variables

Run the following source command to load the environment variables. 

					source /etc/profile.d/

Verify Apache Maven Installation

With that, everything is set up for the Maven, and you verify that everything is installed properly with the following version command. 

					mvn -version

See in the output that the Maven is the latest available version.

That’s it on how you can install Apache Maven on the Ubuntu 20.04 / 22.04 Server. Let’s summarize.

How to Install Apache Maven on Ubuntu 20.04 / 22.04 Server Conclusion

Evidently, Apache Maven is a software project management and comprehension tool. It builds, reports and analyses the project. It provides an integrated set of commands that support the building, distribution and documentation of Java based applications.

Apache Maven is an open-source tool many software developers use to reduce the time they spend compiling, deploying and managing software.

You can also use it to create reusable components that have the potential to integrate with various projects.

Explore our Ubuntu and Apache section to learn more.

Avatar for Sobia Arshad
Sobia Arshad

Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x