Apache Maven 3.9.4

How To Install Apache Maven On Ubuntu 22.04 LTS

In this short tutorial we will learn how to install Apache Maven on Ubuntu 22.04 LTS operating system.

Introduction

In the ever-evolving world of software development, efficient project management and build automation are crucial for success. Apache Maven stands out as a powerful tool that simplifies and streamlines the build process for Java projects. In this article, we’ll explore what Apache Maven is, its key features, and how it has become a cornerstone in Java development.

What is Apache Maven?

Apache Maven, often referred to simply as Maven, is an open-source build automation and project management tool developed by the Apache Software Foundation. It was initially created by Jason van Zyl in 2002 and has since gained widespread adoption in the Java development community.

At its core, Maven provides a comprehensive framework for managing project builds, dependencies, and documentation. It follows a convention-over-configuration approach, meaning that it relies on a set of conventions and defaults to streamline the build process. This approach helps developers focus on their code rather than spending time configuring build settings.

Key Features of Apache Maven

  1. Project Object Model (POM)
    Maven uses a Project Object Model, defined in an XML file named pom.xml, to manage a project’s configuration, dependencies, and build settings. This centralized configuration makes it easy to share and reproduce builds across different environments.
  2. Dependency Management
    Maven simplifies the management of project dependencies. It uses a centralized repository, known as the Maven Central Repository, to store and retrieve project dependencies automatically. Developers only need to specify dependencies in the pom.xml file, and Maven takes care of downloading the necessary libraries.
  3. Build Lifecycle
    Maven defines a set of build phases and goals that facilitate the entire build process. The build lifecycle consists of well-defined phases such as compile, test, package, install, and deploy. Developers can bind plugins and custom tasks to these phases to execute specific actions at different stages of the build.
  4. Plugin Architecture
    Maven’s plugin architecture is extensible and allows developers to integrate various plugins for tasks like compiling code, running tests, generating documentation, and more. This extensibility makes Maven adaptable to a wide range of project requirements.
  5. Convention over Configuration
    Maven promotes convention over configuration, reducing the need for developers to specify build settings manually. By following predefined conventions, Maven can automatically identify the project structure, source directories, and other essential configuration details.
  6. Reproducibility and Consistency
    Thanks to its standardized project structure and build lifecycle, Maven ensures the reproducibility and consistency of builds across different environments. This is crucial for collaborative development and continuous integration practices.

How To Install Apache Maven On Ubuntu 22.04

In this section we will discuss how to install Apache Maven on Ubuntu 22.04 operating system. Before we are starting the installation process, there are several requirements to be fulfilled, namely :

  • Java Development Kit (JDK) Maven 3.3+ require JDK 1.7 or above to execute.
  • Disk Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for our local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB.
  • a system account with sudo privilege.

As mentioned above, if Apache Maven requires Java installed on the system. We will verify it by submitting command line :

$ java --version

Output :

[ramansah@bckinfo ~]$ java --version
openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment (Red_Hat-17.0.8.0.7-1.fc38) (build 17.0.8+7)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.8.0.7-1.fc38) (build 17.0.8+7, mixed mode, sharing)

If our system is not installed Java yet, then we need to install it first by submitting command line :

$ sudo apt install java

The Apache Maven installation on Ubuntu 22.04 steps will be described on several steps as shown below :

  1. Download source & extract files
  2. Setting environment variables
  3. Verify Apache Maven Installation

Step 1: Download Maven and extract the file

The latest stable version of Apache Maven when this tutorial was created is version 3.9.5. We will download Apache Maven from its official web site by submitting command line :

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

Output :

ramansah@bckinfo:~$ wget https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz
--2023-11-14 14:06:19--  https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9359994 (8,9M) [application/x-gzip]
Saving to: ‘apache-maven-3.9.5-bin.tar.gz’

apache-maven-3.9.5-bin.tar.gz  100%[===================================================>]   8,93M   856KB/s    in 15s    

2023-11-14 14:06:35 (622 KB/s) - ‘apache-maven-3.9.5-bin.tar.gz’ saved [9359994/9359994].9.5-bin.tar.gz’ saved [9359994/9359994]

ramansah@bckinfo:~$ ls -ltr *maven*
-rw-rw-r-- 1 ramansah ramansah 9359994 Okt  3 01:06 apache-maven-3.9.5-bin.tar.gz

After source file was downloaded , then we will extract it by using command line :

$ tar -xvf apache-maven-3.9.5-bin.tar.gz

Output :

ramansah@bckinfo:~$ tar -xvf apache-maven-3.9.5-bin.tar.gz
apache-maven-3.9.5/README.txt
apache-maven-3.9.5/LICENSE
apache-maven-3.9.5/NOTICE
apache-maven-3.9.5/lib/
apache-maven-3.9.5/lib/aopalliance.license
apache-maven-3.9.5/lib/commons-cli.license
apache-maven-3.9.5/lib/commons-codec.license
apache-maven-3.9.5/lib/commons-lang3.license
apache-maven-3.9.5/lib/failureaccess.license
apache-maven-3.9.5/lib/guava.license
apache-maven-3.9.5/lib/guice.license
apache-maven-3.9.5/lib/httpclient.license
apache-maven-3.9.5/lib/httpcore.license
apache-maven-3.9.5/lib/jansi.license
apache-maven-3.9.5/lib/javax.annotation-api.license
apache-maven-3.9.5/lib/javax.inject.license
apache-maven-3.9.5/lib/jcl-over-slf4j.license
apache-maven-3.9.5/lib/org.eclipse.sisu.inject.license
apache-maven-3.9.5/lib/org.eclipse.sisu.plexus.license
apache-maven-3.9.5/lib/plexus-cipher.license
apache-maven-3.9.5/lib/plexus-component-annotations.license
apache-maven-3.9.5/lib/plexus-interpolation.license
apache-maven-3.9.5/lib/plexus-sec-dispatcher.license
apache-maven-3.9.5/lib/plexus-utils.license
apache-maven-3.9.5/lib/slf4j-api.license
...
apache-maven-3.9.5/lib/commons-codec-1.16.0.jar
apache-maven-3.9.5/lib/maven-resolver-transport-wagon-1.9.16.jar
apache-maven-3.9.5/lib/maven-slf4j-provider-3.9.5.jar
apache-maven-3.9.5/lib/jansi-2.4.0.jar

Step 2: Set up M2_HOME and Path Environment variables

The next step is to set up the Apache Maven M2_HOME and Path Environment variables. For this purpose we will update the .profile file, then add the following text :

ramansah@bckinfo:~$ vi .profile
...
M2_HOME='/opt/apache-maven-3.9.5'
PATH="$M2_HOME/bin:$PATH"
export PATH

After updating the .profile file, then we can relaunch the terminal or execute source .profile command to apply the configuration changes.

Step 3 : Verify Apache Maven Installation

The last step is to verify if Apache Maven has been installed on our system by querying its version. For nis purpose we will submit the following command line :

$ mvn -version

Output :

ramansah@bckinfo:~$ mvn -version
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /opt/apache-maven-3.9.5
Java version: 11.0.20.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.2.0-36-generic", arch: "amd64", family: "unix"
Apache Maven 3.9.4

At this point, we have successfully installed Apache Maven on Ubuntu 22.04 operating system.

Conclusion

On this short tutorial we have successfully installed Apache Maven version 3.9.5 on Ubunut 22.04 LTS operating system. Apache Maven has become an integral part of Java development, providing a standardized and efficient way to manage builds and dependencies. Its convention-over-configuration philosophy, coupled with a robust plugin architecture, has made Maven a go-to choice for developers aiming to streamline their project workflows. By automating the build process and ensuring consistency, Maven contributes to the overall success and maintainability of Java projects. Whether you’re working on a small open-source project or a large enterprise application, Apache Maven proves to be a valuable asset in the toolkit of every Java developer.

(Visited 86 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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