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.
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.
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.
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 maven.sh in the /etc.profile.d directory using the following command.
sudo nano /etc/profile.d/maven.sh
Paste the following code into the opened maven.sh file.
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.
Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.