How to Install Maven on Ubuntu 24.04 LTS

In this article We are going to cover How to Install JDK on Ubuntu 24.04 LTS, Download and Install Maven on Ubuntu 24.04 LTS and Setup Environment Variables for Maven on Ubuntu 24.04 LTS.

What is Maven?

Apache Maven is a tool for building and managing Java-based projects.

In java based project you have to manage a pom.xml file. It contains information about the project and configuration used by Maven to build the java based project. Everything for your Maven build is defined within pom.xml file.

Prerequisites

  • Ubuntu 24.04 LTS with minimal Installation
  • SSH Access with sudo privileges

Verify Your Ubuntu Distribution

To install the right package on your Linux-based system, such as Ubuntu, check your distribution:

lsb_release -a
How to Install Maven on Ubuntu 24.04 LTS 1

The above command provides detailed information about your Ubuntu release (24.04), codename (noble), etc.

Update Ubuntu’s Packages List

Refresh the packages list of your Ubuntu 24.04 through the command given below:

sudo apt update
How to Install Maven on Ubuntu 24.04 LTS 2

Once your Ubuntu 24.04 machine has refreshed its package list, you will see a similar message as mentioned above.

Step #1:Install Java Development Kit (JDK) on Ubuntu 24.04 LTS

With the Java package, the Maven will run properly. Therefore, you are required to set up the Java default package on your Ubuntu 24.04 machine via the following command:

sudo apt install default-jdk -y
How to Install Maven on Ubuntu 24.04 LTS 3
How to Install Maven on Ubuntu 24.04 LTS 4

During the installation of Java, you can see the required dependencies and libraries have been configured to your system.

Step #2:Verify Java Version on Ubuntu 24.04 using Command line

Let’s execute the following command to confirm the Java package after its installation:

java -version
How to Install Maven on Ubuntu 24.04 LTS 5

You will see the Java Development Kit (JDK) version in your output.

After completing the installation of the Java package, proceed to install the Maven on your Ubuntu 24.04 machine.

The steps presented below will install Maven on your Ubuntu 24.04 machine.

Step #1:Download Maven on Ubuntu 24.04 LTS

To download the latest release of the Maven package, visit maven official website, and copy the link to Maven binary:

https://maven.apache.org/download.cgi
How to Install Maven on Ubuntu 24.04 LTS 6

You can also see the complete address of the Maven binary package at the bottom of the page.

Simply use the “wget” command followed by the URL of the Maven binary, as mentioned below, to download the package:

wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
How to Install Maven on Ubuntu 24.04 LTS 7

The command has successfully downloaded the binary of Maven to your local directory.

Step #3:Install Maven on Ubuntu 24.04 LTS

Next, extract the Maven package to the “/opt” directory using this simple command:

sudo tar xf apache-maven-3.9.9-bin.tar.gz -C /opt
How to Install Maven on Ubuntu 24.04 LTS 8

Encountering no error in your output indicates that the Maven has been successfully extracted to the “/opt” directory of your Ubuntu 24.04 system.

Step #4:Setup Maven’s Environment Variables on Ubuntu 24.04 LTS

On Ubuntu 24.04, setting up environment variables is essential to run the Maven correctly. Therefore, you are required to create a “maven.sh” file to set the environment variables:

sudo nano /etc/profile.d/maven.sh
How to Install Maven on Ubuntu 24.04 LTS 9

Inside the “maven.sh” script file, copy the below lines of code:

export JAVA_HOME=/usr/lib/jvm/default-java 
export M3_HOME=/opt/apache-maven-3.9.9 
export MAVEN_HOME=/opt/apache-maven-3.9.9
export PATH=${M3_HOME}/bin:${PATH}
How to Install Maven on Ubuntu 24.04 LTS 10

Ensure that you have saved the file before returning to the main terminal.

Make the “/maven.sh” Executable

Run the following command to make the “maven.sh” file executable:

sudo chmod +x /etc/profile.d/maven.sh
How to Install Maven on Ubuntu 24.04 LTS 11

This command has made the “maven.sh” script file executable without occurring any errors.

Execute the “/maven.sh” to Apply Changes

source /etc/profile.d/maven.sh
How to Install Maven on Ubuntu 24.04 LTS 12

You will see, no output message on your terminal which indicates that the command was executed successfully.

Verify Maven Installation

To ensure the Maven package is installed correctly, check its version:

mvn -version
How to Install Maven on Ubuntu 24.04 LTS 13

Conclusion:

In this article we have covered How to Install JDK on Ubuntu 24.04 LTS, Download and Install Maven on Ubuntu 24.04 LTS and Setup Environment Variables for Maven on Ubuntu 24.04 LTS

Related Articles:

How to Install Maven on Ubuntu 20.04 LTS

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap