How to Install Apache Maven on Ubuntu 16.04 LTS

On this page

Apache Maven is a software project management tool based on the POM (Project, Object, Model) concept. Maven is a build automation tool used primarily for Java-based projects. It can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.

In this tutorial, I will show you step-by-step how to install and configure Apache Maven on Ubuntu 16.04. We will also learn how to install Java 8 from the PPA Repository.

Prerequisites

Ubuntu 16.04

Root privileges

What we will do

Install Java on Ubuntu 16.04

Download Apache Maven

Configure Apache Maven Environment

Testing

Step 1 - Install Java on Ubuntu 16.04

In this tutorial, we will be using the Java packages from the PPA repository, so we need to add the Java PPA Repository to the system.

Before adding a new repository, install the 'python-software-properties' package using the apt command below.

sudo apt install -y python-software-properties

Now add the Java PPA repository and update all repositories.

sudo add-apt-repository ppa:webupd8team/javasudo apt update

Ubuntu repositories have been updated.

Apache Maven requires the JDK 1.7 or above. And for this guide, we will install the JDK 1.8.

Install java from PPA using the apt command below.

sudo apt install -y oracle-java8-installer

During the installation, you will be prompted about the Oracle Binary License. Choose 'OK'.

Accept the Oracle License by choosing the 'YES' button.

And when the installation is complete, check the java version using the command below.

java -version

You will see a result similar to the following.

Java 8 installed on the Ubuntu 16.04 server.

Step 2 - Download Apache Maven

In this step, we will download the apache maven binary code using the wget command. And we will be using the '/usr/local/src' directory as the Maven home directory.

Go to the '/usr/local/src' directory and download the Apache Maven Binary code.

And you will get new directory apache-maven-version - rename the directory.

mv apache-maven-3.5.2/ apache-maven/

Apache Maven is now downloaded in the '/usr/local/src/apache-maven' directory.

Step 3 - Configure Apache Maven Environment

In this step, we will configure the environment for Apache Maven. We will define some environment variables that are needed by the Apache Maven, including 'JAVA_HOME', M2_HOME, and the PATH environment for the maven binary files.

Go to the '/etc/profile.d' directory and create a new configuration file 'maven.sh'.