How to Install Apache Maven on Ubuntu 18.04

January 04, 2020 No comments Install Maven Ubuntu 18.04 ubuntu

1. What is Maven

Apache Maven provides a complete build management platform for Java-based applications. It describes how the project is built and what dependencies it is using. The main advantage of Maven is the automation of the application development process. The only thing developers have to do is to follow the directory naming convention in their projects. Maven will take care of downloading the latest dependencies, compiling the code, performing tests, etc.

In this tutorial, we will show you how to install Apache Maven on Ubuntu 18.04, however, those instructions should apply also for Ubuntu in version 16.04.

2. Prerequisites

Ubuntu account with the sudo privileges.

3. Installing Apache Maven on Ubuntu with apt

The official Ubuntu repositories include Maven package that can be installed with the apt command. However, the version included in the repositories may be a bit obsolete than what is available on the official Maven website. To install Maven using apt follow these steps:

3.1. First update the package index

sudo apt update

3.2. Next, install Maven by typing the following command

sudo apt install maven

3.3. Check if the Apache Maven has been successfully configured

mvn -version

The output of this command should look like this:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 1.8.0_181, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-38-generic", arch: "amd64", family: "unix"

Note that the version of Apache Maven in your output may be different as well as the Java version.

3.4. Where is Maven located in filesystem?

Installing Maven with apt will put all necessary files into /usr/share/maven and /etc/maven directory. You can use ls -la command to print out that files.

ls -la /usr/share/maven
drwxr-xr-x   6 root root  4096 Nov   9 17:34 .
drwxr-xr-x 227 root root 12288 Nov   9 17:34 ..
drwxr-xr-x   2 root root  4096 Nov   9 17:34 bin
drwxr-xr-x   2 root root  4096 Nov   9 17:34 boot
lrwxrwxrwx   1 root root    10 Feb  24  2018 conf -> /etc/maven
drwxr-xr-x   2 root root  4096 Nov   9 17:34 lib
drwxr-xr-x   2 root root  4096 Nov   9 17:34 man
ls -la /etc/maven
drwxr-xr-x   3 root root  4096 Nov   9 17:34 .
drwxr-xr-x 127 root root 12288 Nov   9 17:34 ..
drwxr-xr-x   2 root root  4096 Nov   9 17:34 logging
-rw-r--r--   1 root root   220 Okt  18  2017 m2.conf
-rw-r--r--   1 root root 10211 Okt  18  2017 settings.xml
-rw-r--r--   1 root root  3645 Okt  18  2017 toolchains.xml

And that’s it. You can now start using Maven on your system.

4. Conclusion

In this article we showcased how to easily install Maven on Ubuntu in version 18.04 or 16.04 using apt (Advanced Packaging Tool).

{{ message }}

{{ 'Comments are closed.' | trans }}