Linux Tactic

Installing Apache Maven on Debian-based Linux: A Comprehensive Guide

If you are a developer who uses Java for your projects, you may have heard of Apache Maven. Apache Maven is a powerful tool that can help you manage your project’s build process and dependencies.

In this article, we will guide you through the process of installing Apache Maven on a Debian-based distribution of Linux.

Installing Apache Maven with apt

Before we dive into the installation process, let’s go over the prerequisites. First, you will need to have root or sudo privileges on your system.

Second, you need to have the package index updated. Once you have met these two requirements, you can proceed to install Apache Maven using apt.

To install Apache Maven, open a terminal window and run the following command:

“`

sudo apt update

sudo apt install maven

“`

This will download and install Apache Maven for you. To verify that the installation was successful, run the following command:

“`

mvn -version

“`

You should see output similar to the following:

“`

Apache Maven 3.6.3

Maven home: /usr/share/maven

Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64

Default locale: en_US, platform encoding: UTF-8

OS name: “linux”, version: “5.8.0-63-generic”, arch: “amd64”, family: “unix”

“`

If you see output like this, congratulations – you have successfully installed Apache Maven!

Installing the Latest Release of Apache Maven

If you want to install the latest release of Apache Maven, you will need to follow a slightly different process. Before we begin, let’s go over the prerequisites again.

You will need to have JDK 1.7 or higher installed on your system. For this article, we will be using OpenJDK 11.

Downloading Apache Maven

To download Apache Maven, open a terminal window and run the following commands:

“`

wget http://mirror.nohup.it/apache/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz

“`

This will download the Apache Maven archive to your home directory. Next, extract the archive by running the following command:

“`

tar -xf apache-maven-3.8.2-bin.tar.gz

“`

This will create a new directory called `apache-maven-3.8.2`.

We need to move this directory to `/opt`, which is where we will install Apache Maven. To do this, run the following command:

“`

sudo mv apache-maven-3.8.2 /opt/

“`

Now that we have Apache Maven installed, we need to create a symbolic link to the `mvn` command.

This will allow us to run Maven from anywhere on our system. To create the symbolic link, run the following command:

“`

sudo ln -s /opt/apache-maven-3.8.2/bin/mvn /usr/local/bin/mvn

“`

Setting up environment variables

Next, we need to set up some environment variables so that Maven knows where to look for its dependencies. To do this, we will create a new file called `maven.sh` in `/etc/profile.d/`.

Open a terminal window and run the following command:

“`

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

“`

This will open a text editor where you can enter the following lines:

“`

export M2_HOME=/opt/apache-maven-3.8.2

export PATH=${M2_HOME}/bin:${PATH}

“`

Save the file and exit the text editor. Now we need to run the `source` command to ensure that the new environment variables are loaded.

Run the following command:

“`

source /etc/profile.d/maven.sh

“`

Verifying the installation

Finally, we need to verify that the installation was successful. Open a terminal window and run the following command:

“`

mvn -version

“`

You should see output similar to the following:

“`

Apache Maven 3.8.2

Maven home: /opt/apache-maven-3.8.2

Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64

Default locale: en_US, platform encoding: UTF-8

OS name: “linux”, version: “5.8.0-63-generic”, arch: “amd64”, family: “unix”

“`

If you see output like this, congratulations – you have successfully installed the latest release of Apache Maven!

Conclusion

In this article, we have shown you how to install Apache Maven on a Debian-based distribution of Linux. We covered two methods – installing with apt and installing the latest release.

No matter which method you choose, Apache Maven is a powerful tool that can help you manage your Java projects with ease. We hope that this article has been informative and helpful, and that you are now ready to start using Apache Maven in your own projects!

This article provided a comprehensive guide on how to install Apache Maven on a Debian-based distribution of Linux.

Two methods were presented – installing with apt and installing the latest release. Apache Maven is a powerful tool that can help you manage your Java projects with ease.

The article emphasized the importance of having this tool in your arsenal as a developer and provided practical steps to get started. Regardless of your preferred method, successful installation of Maven empowers you to manage project dependencies and builds with ease.

Whether you are a seasoned developer or just starting out, this article can serve as a useful reference to help you master Apache Maven.

Popular Posts