Introduction:

Apache Maven is an open-source project management and comprehension tool used primarily for Java projects. Maven uses a Project Object Model (POM), which is essentially an XML file containing information about the project, configuration details, the project’s dependencies, and more.

The official Ubuntu repositories contain Maven packages that can be installed with the apt package manager. This is the easiest way to install Maven on Ubuntu. However, the version included in the repositories may lag behind the latest version of Maven.

To install the latest version of Maven, follow the instructions provided in this article that shows how to download the binary distribution archive from their official website.

Choose the installation method that is most appropriate for your setup and environment.

Prerequisites:

A system running Ubuntu 20.04.

A working Internet connection.

Access to a text editor such as Nano.

Installing Apache Maven on Ubuntu 20.04 with apt

Installing Maven on Ubuntu using apt is a simple, straightforward process.

first we need to update the package index and install Maven by entering the following commands:

sudo apt update
sudo apt install maven

To verify the installation, run mvn -version:

mvn -version

The output should look something like this:

That’s it. Maven is now installed on your system.

Installation of the Latest Release of Apache Maven 20.04

In this section, we’ll provide a step by step instructions about how to download and install the latest Apache Maven version on Ubuntu 20.04.

1. Install OpenJDK :

we need to update the package index and install jdk by entering the following commands:

sudo apt update
sudo apt install default-jdk

Verify the installation by running the following command:

java -version

The output is look like this:

2. Downloading Apache Maven :

the latest version of Apache Maven is 3.9.4. Before continuing with the next step, visit the maven download page to see if a newer version is available.

Download the Apache Maven in the /tmp directory:

wget https://www-us.apache.org/dist/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz -P /tmp

Once the download is completed extract the archive in the /opt directory:

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

3. Setup environment variables

Next, we’ll need to set up the environment variables. To do so, open your text editor and create a new file named maven.sh in the /etc/profile.d/ directory.

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

Paste the following code:

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. This script will be sourced at shell startup.

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

Finally, load the environment variables using the source command:

source /etc/profile.d/maven.sh

4. Verify the installation:

To verify that Maven is installed, use the mvn -version command which will print the Maven version:

mvn -version

The output will be:

That’s it. The latest version of Maven is now installed on your Ubuntu system.

Conclusion :

We have shown you how to install Apache Maven on Ubuntu 20.04. You should now visit the official Apache Maven Documentation page and learn how to get started with Maven.

This process ensures that you have the latest version of Apache Maven installed on your Ubuntu 20.04 system, making it ready for use in managing your Java projects and build automation tasks.

Any queries pls contact us:
https://rushiinfotech.in/contact/

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *