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.
Table of Contents
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
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
Once your Ubuntu 24.04 machine has refreshed its package list, you will see a similar message as mentioned above.
Install Java Development Kit (JDK) for Maven on Ubuntu 24.04 LTS?
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
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
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.
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: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
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
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
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
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}
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
This command has made the “maven.sh” script file executable without occurring any errors.
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.
Verify Maven Installation
To ensure the Maven package is installed correctly, check its version:
mvn -version
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: