Javatpoint Logo
Javatpoint Logo

Install Maven in Ubuntu

What is Maven?

Maven is a tool of build automation used mainly for Java projects. Also, it can be used for building and managing projects which are written in is Scala, Ruby, C#, and other languages. The project of Maven is hosted via the Apache Software Foundation, in which it was the Jakarta Project part.

Maven defines two aspects of establishing software: how software is established and its dependencies. It applies conventions for the establishment procedure, unlike earlier tools such as Apache Ant. Only exceptions are required to be described. An XML file defines the software project being established and its dependencies on many other external components and modules, the build directories, order, and required plug-ins. It provides the pre-defined code and packaging.

  • Dynamically, Maven downloads Maven plugins and Java libraries from multiple repositories like the Maven 2 Central Repository and saves them in the local cache.
  • Also, this local cache of installed artifacts can be updated with many artifacts made by local projects.
  • Also, public repositories can be updated.
  • Maven is created with the plug-in architecture that permits it for making use of an application that is controllable from standard input.
  • The native plug-in of C/C++ is organized for Maven 2.
  • Many alternative technologies such as sbt and Gradel, because build tools don't depend on XML, but have the key concepts that Maven introduced.
  • A dependency manager was developed that supports the repositories of Maven as well with Apache Ivy.

Design of Maven

Install Maven in Ubuntu

Project Object Model (POM)

A project object model facilitates every configuration for one project. The basic configuration covers the name of the project, its dependencies, and its owner on other projects, Also, one can configure a single phase of a build process, which is worked as plugins. For instance, one can construct the compiler plugin for using the 1.5 version of Java for compilation or describe the project packaging even when a few unit tests break down.

Bigger projects should be categorized into many sub-projects and modules, each with its POM. Then, one can specify a root POM from which one can compile every module with one command. Also, POMs can acquire configuration from any other POM. Every POM by default acquires from its super POM. The super POM gives default configurations like default plugins, default source directories, etc.


Most functionality of Maven is inside the plugins. A plugin gives a group of goals that could be run with the help of the mvn [plugin-name] : [goal-name] command. For instance, a project of Java could be compiled with the compile-goal of compiler-plugin by executing the mvn compiler:compile command.

There are many Maven plugins to build, test, run a web server, source control management, produce Eclipse project files, etc. These plugins are configured and introduced in the section, i.e., <plugins> of the pom.xml file.

A few basic plugins are by default added in all projects and they have logical default settings. It however would be inconvenient if the archetypal build sequence of packaging, testing, and building a software project needed manually executing all respective goals:

  • mvn compiler:compile
  • mvn surefire:test
  • mvn jar:jar

The lifecycle concept of Maven manages this problem.

A plugin is the main way for extending Maven. Integrating a Maven plugin could be implemented by extending a class, i.e., org.apache.maven.plugin.AbtractMojo.

Build lifecycles

It is a named phases list that could be used for giving sequence to goal implementation. One of the standard lifecycles of Maven is a default lifecycle, which has some phases in a particular order, which is mentioned as follows:

  • Lifecycle 1: validate
  • Lifecycle 2: generate-sources
  • Lifecycle 3: process-sources
  • Lifecycle 4: generate-resources
  • Lifecycle 5: process-resources
  • Lifecycle 6: compile
  • Lifecycle 7: process-test-sources
  • Lifecycle 8: process-test-resources
  • Lifecycle 9: test-compile
  • Lifecycle 10: test
  • Lifecycle 11: package
  • Lifecycle 12: install
  • Lifecycle 13: deploy

Goals given by plugins could be connected with different lifecycle phases. For example, the compiler:compile goal is by default connected with the phase, i.e., compile, while the surefire:test goal is connected with the phase, i.e., test. When the command, i.e., mvn test is run, Maven executes every goal connected with all phases up to and adding the 'test' phase.

Maven executes the goal, i.e., resources:resources connected with the phase, i.e., process-resources, then compiler:compile, etc until it finally executes the goal, i.e., surefire:test.

Also, Maven contains standard phases to clean the project and generate a project site. The project will be cleaned all time it was created if cleaning were the default lifecycle part. It is undesirable, hence cleaning has been provided its lifecycle.


Dependency management is a central aspect of Maven. The dependency-handling mechanism of Maven is organized across a coordinate system recognizing individual artifacts like software models or libraries.

Installing Maven in Ubuntu 20.04

Apache Maven is an exclusive and advanced tool in the creation of projects typically corresponding to Java. It's an open-source tool that uses the Project Object Model encompassing an XML file for retailing the crucial information of a project, that culminates within the information related to the art project, configuration files, and its dependencies.

We will require common knowledge over the commands and working of Linux, sudo commands recognizing, and the root user privileges for effectively installing Maven on the 20.04 version of Ubuntu. This tool is created for assisting its user in creating projects by reporting and documenting the central project regarding information proficiently.

Maven qualifies as a best-suited tool to manage Java projects. Also, it contains built-in object commands for dealing with the code composition and packages.

Installation Process of Maven

The installation process of Maven is short composite on three basic steps. Before starting these three steps, we can avail every benefiting aspect of Maven for managing the Java projects on our Ubuntu system.

Step 1: Package up-gradation

Step 2: Apache Maven installation

Step 3: Verification


It's mandatory to have Java installed in our server with the Java encompassing JRE and JDK development kit to execute the Maven commands. If we do not have Java installed in our system, then we can run the following command in the terminal window:

Install Maven in Ubuntu

Also, we can verify the Java system installation and its kit with the help of the following command:

Install Maven in Ubuntu

Step 1: Package up-gradation

First of all, we need to update our existing packages with the help of the sudo apt command. It's fundamental for updating our existing packages before going to install any server or tool on the Ubuntu system. The command is mentioned below:

Install Maven in Ubuntu

Also, we can execute this command before going to install the Java kit. The system packages would be updated with the Java kit installation using this way.

Step 2: Apache Maven installation

Primarily, there are two methods to get Maven in our system. Either, we can download it using the apt command or using its web source directly from the wget command.

We need to run the following command in the terminal window to install Maven:

Install Maven in Ubuntu

Step 3: Verification

Also, we can verify Maven installation with the help of the following command in the terminal window:

Install Maven in Ubuntu

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA