How to Install Apache Maven on Ubuntu?

15-Jun-2023

.

Admin

How to Install Apache Maven on Ubuntu?

Hello Friends,

In this tutorial we will go over the demonstration of how to install apache maven on Ubuntu. you'll learn how to install Maven on linux. I explained simply step by step installing apache maven on Ubuntu. This post will give you a simple example of how to install Apache Maven.

To install Apache Maven on Linux Ubuntu 22.04, follow this tutorial. We will learn how to install Apache Maven on Linux Ubuntu 22.04.

Step 1: Install OpenJDK


First of all, Open the terminal application by pressing Ctrl+Alt+T.

Then execute the following command on the command line to install OpenJDK on the linux ubuntu system:

sudo apt update

sudo apt install default-jdk

Verify the installation by executing the following command on the command line:

java -version

Step 2: Downloading Apache Maven

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.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

Once the download is finished, extract the archive in the /opt directory:

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

To have more control over Maven versions and updates, we will create a symbolic link Maven that will point to the Maven installation directory:

sudo ln -s /opt/apache-maven-3.6.3 /opt/maven

Step 3: Setup environment variables

Set up the environment variables. 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

Then add the following code into it:

export JAVA_HOME=/usr/lib/jvm/default-java

export M2_HOME=/opt/maven

export MAVEN_HOME=/opt/maven

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

Make the script executable with chmod:

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

Finally, load the environment variables using the source command:

source /etc/profile.d/maven.sh

Step 4: Verify the installation

Execute the following command on the command line to verify maven installation:

mvn -version

I hope it can help you...

#Ubuntu