How to Install Apache Maven on Ubuntu

This brief guide shows how to install Apache Maven on Ubuntu Linux. If you are a beginner or a new user and want to install Apache Maven on your ubuntu Linux machine then this short tutorial is useful and handy for you.

Apache Maven is a free, powerful and open source software project management and comprehension tool that is used primarily for Java projects.

It is based on the concept of POM (project object model) that helps you to manage an entire project’s build process, including storing documents, reporting and more. Basically POM (project object model) is an XML file which is containing information about the project, configuration details, the project’s dependencies, and many more.

Sponsored

Installing Apache Maven on Ubuntu Linux is very easy and straightforward because Maven packages are available in Ubuntu official repositories. So you just need to run the apt get commands to install it in your Ubuntu system.

The versions installed using apt package manager may not necessarily be the latest versions. If you really want to install the latest version of Maven then you need to download and install it manually yourself.

In this tutorial, we are going to use two methods for installing Skype:

  1. Install Apache Maven via apt package manager
  2. Install Apache Maven manually.
See also  Top New Features in GNOME 46, the Desktop for Ubuntu 24.04

Method 1 : Install Apache Maven with apt on Ubuntu Linux

As mentioned above, installing Apache Maven on Ubuntu Linux using apt package manager is very easy and straight-forward process. You just need to follow below steps:

Step 1 : Update the Package Index

sudo apt update

Step 2 : Install Apache Maven

sudo apt install maven

When you run the command above, it will install the Apache Maven with all required dependencies.

Step 3 : Verify the Installation:

mvn -version

The command above will display a output similar like below:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.2, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8

Method 2 : Install the Latest Version of Apache Maven Manually 

Using this method, you can get the latest version of Maven in your ubuntu system. To do that, follow the steps below:

Step 1: Install OpenJDK

Apache Maven is based on Java. So its require JDK (Java Development Kit) to be installed. For this, we will install OpenJDK by running the command below:

sudo apt update
sudo apt install default-jdk

To verify the OpenJDK installation, run the command below:

java -version

Step 2 : Download Apache Maven

At the time of writing this guide, the latest version of Apache Maven is 3.8.3. You can check the Maven – download page to see the latest versions.

To download the latest version( 3.8.3 ), run the command below:

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

After download, extract the downloaded archive in the /opt directory by running command below:

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

Next, create a symbolic link to the version folder to control Maven versions and updates. To that, run the command below:

Sponsored
sudo ln -s /opt/apache-maven-3.8.3 /opt/maven

The command above will create a symbolic link maven that will point to the installation directory.

Later when the new version is released, you just need to extract the newer version and change the symbolic link to point to the latest version.

Step 3 : Setup Maven Environment Variables

After that, you will need to set up its environment variables. To do that, create a new file named maven.sh by running command below:

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

The new file created inside the /etc/profile.d/ directory.

Next, copy and pastes the below configuration into the new 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}

Save and close the file.

Next, run the commands below to make the script executable and load the environment variables:

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

Step 4 : Verify the Maven installation 

You can verify the Maven installation by display its version. To do that, run the command below:

mvn -version

It will display a output similar like below:

Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /opt/maven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8

That’s all

If you find any error and issue in above steps , please use comment box below to report.

If our article helps you, please consider buying us a coffee

Thank you for your support.

The post How to Install Apache Maven on Ubuntu appeared first on Linux Tutorial Hub.

Leave a Comment

Only people in my network can comment.