Greenwebpage Community Blog Tutorials How to Install Maven on Ubuntu 24.04
Tutorials

How to Install Maven on Ubuntu 24.04

Maven, or Apache Maven, is a popular automation utility mainly used for Java projects. The main objectives of Maven are simplifying building, managing dependencies, and streamlining project documentation.

Moreover, you can easily handle multiple projects simultaneously. This technical post aims to illustrate how to install the latest version of Maven (3.9.7) on Ubuntu 24.04 system.

How to Install Maven on Ubuntu 24.04?

Through this technical guide, you will learn about:

  • How to Install Java Development Kit (JDK) for Maven on Ubuntu 24.04?
  • How to Install Maven on Your Ubuntu 24.04 System?

Step 1: Verify Your Ubuntu Distribution

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

lsb_release -a

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

Step 2: Update Ubuntu’s Packages List

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

sudo apt update

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

How to Install Java Development Kit (JDK) for Maven on Ubuntu 24.04?

Following are some essential commands for installing Java Development Kit (JDK) for Maven on your Ubuntu 24.04 system.

Step 1: Install Java Development Kit (JDK)

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
 

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

Step 2: Confirm Java Installation

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

java -version

You will see the Java Development Kit (JDK) version like “21.0.3” in your output.

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

How to Install Maven on Your Ubuntu 24.04 System?

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

Step 1: Visit the Maven Official Website

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

https://maven.apache.org/download.cgi

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

Step 2: Download Maven Binary

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.7/binaries/apache-maven-3.9.7-bin.tar.gz

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

Step 3: Extract Maven to “/opt” Directory

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

sudo tar xf apache-maven-3.9.7-bin.tar.gz -C /opt

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, 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

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.7 
export MAVEN_HOME=/opt/apache-maven-3.9.7 
export PATH=${M3_HOME}/bin:${PATH}

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

Step 5: Make the “/maven.sh” Executable

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

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

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

Step 6: Execute the “/maven.sh” to Apply Changes

Finally, you are required to execute the “maven.sh” file and apply changes without rebooting your system.:

source /etc/profile.d/maven.sh

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

Step 7: Verify Maven Installation

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

mvn -version

The “Apache Maven 3.9.7” confirms that you have successfully installed the latest available version of Maven on your Ubuntu 24.04 system.

Conclusion

You can install the latest version of Maven (i.e. 3.9.7) on your Ubuntu 24.04. To download the binary of Maven, visit the Maven website, copy the link, and download using the “wget” command. Next, set up an environment variables file (i.e. maven.sh) and execute to configure the Maven on your Ubuntu 24.04 system.

Exit mobile version