How To Install Apache Maven on Ubuntu 20.04

Apache Maven is a framework for automating the assembly of projects based on the description of their structure in files in the POM language, which is a subset of XML. The Maven project is published by the Apache Software Foundation community, where it is formally part of the Jakarta Project. Apache Maven is a dedicated open-source project management tool that is used for Java projects. You can easily manage project builds, reporting, and documentation from a central piece of information using Apache Maven.

The first step to complete the installation is to update your system to the latest stable version:

sudo apt-get update -y
sudo apt-get upgrade -y

Java Installation

Maven 3.6.3 or higher requires JDK 1.7 or higher installed. We will install OpenJDK, which is the default Java development and runtime environment on Ubuntu 20.04. First, install OpenJDK:

sudo apt-get install -y default-jdk

After that, you should check the Java version

java -version

The output will be similar to the following:

openjdk version "" 2020-11-04
OpenJDK Runtime Environment (build
OpenJDK 64-Bit Server VM (build, mixed mode, sharing)

Apache Maven Installation

The next step will be followed by the actual installation of Apache Maven. The first step is to change your working directory to /opt/ directory:

cd /opt/

Install Apache Maven can be installed from the official website. Installation is described in the command below:

sudo wget

After successful completion of the download, you can unpack the downloaded archive using the command below:

sudo tar -xvzf apache-maven-3.6.3-bin.tar.gz

Then rename the extracted directory:

sudo mv apache-maven-3.6.3 maven

Installation environment variables

After the given resource has been successfully installed, you need to set up environment variables such as PATH, M2_HOME, JAVA_HOME. You can do this by creating a file inside the /etc/profile.d/ directory:

sudo vi /etc/profile.d/

Then, you should add what is described below:

export JAVA_HOME = / usr / lib / jvm / default-java
export M2_HOME = / opt / maven
export PATH = $ {M2_HOME} / bin: $ {PATH}

Then you need to save and close the file and make it executable:

sudo chmod + x /etc/profile.d/

Now you can load the environment variables:

source /etc/profile.d/

Was this article helpful?

Related Articles

Leave A Comment?