December 3, 2021
How to install apache Maven on Ubuntu Linux

How To Install Apache Maven On Ubuntu 20.04 LTS

On this article we will discuss how to install Apache Maven on Linux Ubuntu 20.04 LTS.

Introduction

Apache Maven is an open-source project management software and comprehension tool used primarily for Java projects. Maven is built based on the concept of a project object model (POM), Maven can manage a project’s build, configuration details, the project’s dependencies, reporting and documentation from a central piece of information. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project. The last version of Apache Maven is 3.6.3 released on 25 November 2019.

Indeed, the official Ubuntu repositories has already contained Apache Maven packages which can be installed on our Ubuntu system. However, the version included in the repositories may be left behind the latest version of Maven, so we will use the Maven package from Apache Ubuntu repositories. The Apache Maven installation steps will be described on several steps.

  1. Prerequisite
  2. Installation include : download source, extract files and setting environment variables
  3. Verifying Apache Maven Installation

Prerequisite

System Requirements

Apache Maven requires any system requirements :

  • Java Development Kit (JDK) Maven 3.3+ require JDK 1.7 or above to execute – they still allow you to build against 1.3 and other JDK versions by Using Toolchains
  • Disk Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for your local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB
  • root account or user with sudo privilege.

If we have no Java installed on our system, just install it first. The Java installation has discussed on How To Install Java (OpenJDK 11) on Ubuntu 20.04 LTS article. first, we verify our Java version installed on our system, for this purpose we will submit command line.

ramans@otodiginet:~$ java --version

Apache Maven Installation

1. Download
The installation process will be starting by downloading the Apache Maven source file from the official page, https://maven.apache.org/download.cgi .
At our case, the package file will be stored on /home/ramans directory.

ramans@otodiginet:~$ wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /home/ramans

Download Apache Maven files

2. Extract source code
The package was put on my home directory, then we will extract the file and we will make symbolic link.

ramans@otodiginet:~$ cd /home/ramans
ramans@otodiginet:~$ tar xzf apache-maven-3.6.3-bin.tar.gz

Maven source package

After the file has been extracted, the files will be located on /home/ramans/apache-maven_3.6.3 directory. then we will create symbolic link.

ramans@otodiginet:~$ sudo ln -s apache-maven-3.6.3 maven

3. Setup Environment Variables
The next step, we must set up the environment variables. To do so, open text editor and create a new file named mave.sh in the /etc/profile.d/ directory and put the content as below. (There will be vary for the Maven source file directory)

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export M2_HOME=/home/ramans/maven
export MAVEN_HOME=/home/ramans/maven
export PATH=${M2_HOME}/bin:${PATH}

Then we have to make the file and load the environment variables in current shell.

ramans@otodiginet:~$ sudo chmod +x /etc/profile.d/maven.sh
ramans@otodiginet:~$ source /etc/profile.d/maven.sh

Verify Maven Installation

After all step was passed, then we will verify Apache Maven installation by querying Maven version, by submitting command line below.

ramans@otodiginet:~$ mvn --version

the output will be :

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/ramans/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-39-generic", arch: "amd64", family: "unix"
Maven version 3.6.3

Conclusion

The Apache Maven installation has completed done, for other resource on Apache Maven, we could find on Apache Maven official page. Have a nice day..

Share this article via :

Leave a Reply

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