Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Maven
3.
Prerequisites
4.
Installing Maven with Apt
5.
Manually Installing Maven
6.
Frequently Asked Questions 
6.1.
What is Maven?
6.2.
What are the aspects managed by Maven?
6.3.
What are the minimum required elements for the Project Oriented Model?
6.4.
What is POM?
6.5.
What is a Maven repository?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

How to install Maven on Ubuntu

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Hello Ninja! We heard that you were looking for a way to install Maven on your Ubuntu system. Don't worry! You will find all that you need in this article. In this section, we will discuss Maven’s installation on Ubuntu using two ways.

Introduction

Maven

It is a command-line tool that is built on the Project Object Model (POM). It is used to make and manage projects in Java. You can obtain the dependencies required for the project with the aid of Maven. Since Maven is written in Java, we must install and configure Java for it to run.  

Maven

Let us start by taking a look at some system needs.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Prerequisites

Before we start, you need to make sure that you have all these prerequisites:

  •  A system with Ubuntu.
     
  • Internet connection.
     
  • Access to an account with Sudo privileges. Sudo privileges, allow you to temporarily escalate your current user account to obtain root rights.
     
  • Access to the terminal window.
     
  • Access to a text editor
     

If you have all these handy, you're good to go. Let's start to install Maven on Ubuntu using the APT.  APT, or Advanced Package Tool, is a group of tools for installing, updating, removing, and managing software packages. To carry out its operations, APT uses repositories or special directories. They are used to keep collections of software packages. Now start with Install Maven on Ubuntu from the next topic.

Installing Maven with Apt

You can install Maven on Ubuntu in a quick and easy way through the apt command. For this, you must follow these steps.
 

Step-1: Update the system repositories

Open the terminal on Ubuntu and type the command that follows:

sudo apt update


After this command, your terminal screen will look like this:

output of update

Also, upgrade the system packages by

sudo apt upgrade


You will see something like this on the terminal:

output of upgrade

Step- 2: Install Maven

Install Maven on Ubuntu from the official repository using the command that follows:

sudo apt install maven -y


After this command, the terminal screen will look something like this:

output for apt install maven

Step- 3: Verifying installation

Verify the installation by checking Maven's current version with the command that follows:

mvn -version


If the installation was a success, the output which is shown in the image below will be displayed:

mvn version output

And, you're done.

Let's move on and see how we can install Maven on Ubuntu with the use of the manual method. Although it is a bit hard, it offers more fluidity in which version to install.

Check this out, pwd command in linux

Manually Installing Maven

Expert Linux users prefer the manual method to install Maven on Ubuntu. This method lets you download and install the most recent version.

Step- 1: Install Java

Make sure that Java is already installed on your system before moving ahead. If it's not, then use the command that follows to install it:

sudo apt install default-jdk -y


Java installation will start after this command, and your screen will appear something like this:

output of sudo apt install default-jdk -y

You can confirm the installation by checking the current version of Java by the use of this command:

java -version


Upon successful installation of java, the output screen after that command will look like this:

output of java-verison

If you already have Java installed on your system, skip this step and move on to the next one.


Step- 2: Download and Install Apache Maven

Visit the download page for Maven. Now, select the version that you want to install. The "files" section contains the most recent version. You can find the older versions through the "archive" link in the "previous releases" section.

Once you choose which version to install, copy its link and install it in the /tmp directory using the command that follows:

We're using version 3.8.6.

wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz -P /tmp


You'll see this on your screen:

output of wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz -P /tmp

Once you are done with the download, you will need to extract the downloaded file into the /opt directory using this command:

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt


Make a symbolic link called maven. It will point to the Maven installation directory. You can do it by using the command that follows:

sudo ln -s /opt/apache-maven-3.8.6 /opt/maven


After using the above-mentioned commands, you will see this on your terminal window:

output of sudo ln -s /opt/apache-maven-3.8.6 /opt/maven

Step- 3: Set up environment variables.

The next step will involve configuring the environment variables. We will do it by generating the "maven.sh" Maven script file in the "/etc.profile.d" directory. For the same purpose, we will employ the nano text editor.

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


The text editor will open up and your screen will look like this:

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

Paste the code that follows into the "maven.sh" 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}


After writing this script, Press Ctrl + X, followed by Y. Your screen should look like the image that follows

output of 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 enter to save the changes to maven.sh.

To make the created Apache Maven script executable, we will use the chmod command:

sudo chmod +x /etc/profile.d/maven.sh


After that, use the "source" command to load the environment variables as follows:

source /etc/profile.d/maven.sh


The output of the above two commands will look like this:

output of sudo chmod +x /etc/profile.d/maven.sh and source /etc/profile.d/maven.sh

Step- 4: Verifying Installation

To verify the installation, check the current version of Maven by

mvn -version


If the installation was successful, you will get this output on your screen:

Verifying Installation

Voila! Now you now have maven installed on your system.

As we have covered the topic Install Maven on Ubuntu you might be able to Install Maven on Ubuntu. If you still face any problems please comment so that we can help you out.

Frequently Asked Questions 

What is Maven?

Maven is a project management tool developed by the Apache Software Foundation. It provides an entire build cycle framework.

What are the aspects managed by Maven?

Documentation, builds, SCMs, releases, distribution, mailing lists, dependencies, and reporting are the aspects that Maven manages.

What are the minimum required elements for the Project Oriented Model?

Project root, modelVersion, groupID, artifactID, and version are the bare essentials for a Project Oriented Model.

What is POM?

POM, or project object model, is a fundamental component of how Maven functions. The pom file in the current directory is checked for information about the project while carrying out a Maven objective or task.

What is a Maven repository?

The Maven repository is where all the relevant project artifacts, jars, libraries, and plugins are stored and conveniently accessible to Maven.

Conclusion

We have discussed two ways to install Maven on Ubuntu in this article. You can either use "apt" or the manual installation process. You can select whichever method suits you the best.

We hope this article helps you on your journey. Here are some additional articles for your consideration:

You can refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more!

Head over to our practice platform, Coding Ninjas Studio, to practice top problems, attempt mock tests, read interview experiences and interview bundles, follow guided paths for placement preparations, and much more.

Happy Learning!

Previous article
How to Install Maven on Windows
Next article
How to install Maven on Mac OS
Live masterclass