How to Install and Use Apache Maven on Ubuntu 22.04?

Sep 01, 2022 . Admin



Hi Guys,

In this example, I will show you How to Install and Use Apache Maven on Ubuntu 22.04?. We will look at example of Install Apache Maven on Ubuntu 20.04 Example. I would like to show you Step by Step Install Apache Maven on Ubuntu 22.04. I’m going to show you about Configure and Install Apache Maven on Ubuntu 22.04 LTS Example. Let's see bellow example 4 Best ways to Install and Run Apache Maven on Ubuntu 22.04.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Use the following steps to install apache maven on Linux ubuntu 22.04:

Step 1: Install OpenJDK

Step 2: Downloading Apache Maven

Step 3: Setup environment variables

Step 4: Verify the installation

Step 1: Install OpenJDK

Open terminal and execute the following command on command line to install openJDK on linux ubuntu system::

sudo apt update
sudo apt install default-jdk

The installation by executing the following command on command line:

java -version
Step 2: Downloading Apache Maven

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

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

The environment variables need to be set, and this can be done by creating maven.sh under the /etc/profile.d/ directory.

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

Next, add the following to the file.

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

The environment variables using the source command:

source /etc/profile.d/maven.sh
Step 4: Verify the installation

Finally, check the installed version:

mvn -version
#Ubuntu