How to Install Apache Maven on Ubuntu 18.04

r00t July 18, 2018

Install Apache Maven on Ubuntu 18.04

In this tutorial we are going to learn how to install Apache Maven on Ubuntu 18.04. We will also install and configure its prerequisites. Apache Maven is a project management tool for handling, construction, reporting and documenting of Java-based improvement project. It comprises a project object model, a set of criteria, a project lifecycle, a dependency management system and logic. Maven is designed to provide a simple project set up for users to have an easy environment.Maven addresses two parts of building a program, it first clarifies the way the software is assembled and second its dependencies.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache Maven on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

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

Step 2. Installing Java.

Apache Maven requires Java 1.7 or greater. For this reason, you can install OpenJDK 8 as follows:

sudo add-apt-repository ppa:webupd8team/java

Next, Install the latest stable version of Oracle Java 8:

sudo apt-get update
sudo apt-get install oracle-java8-installer

Run the following command to verify the installation of Java:

### java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Step 3. Installing Apache Maven on Ubuntu 18.04 Bionic Beaver.

First, Go to their official website and download the archive of the desired version. In this tutorial we will install Apache Maven version 3.5:

wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

Now extract the downloaded archive using the TAR command:

sudo tar -zxvf apache-maven-3.5.4-bin.tar.gz
sudo mv apache-maven-3.5.4 /opt/maven

After you have moved precompiled Apache Maven files on your system, you will need set the environments variables by creating a maven.sh file under /etc/profile.d/ directory:

nano /etc/profile.d/maven.sh

Add following content:

export JAVA_HOME=/usr/jdk1.8.0_151/
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Now load the environment variables:

source /etc/profile.d/maven.sh

With this step Apache Maven should be successfully installed and configured on your Ubuntu 18.04 LTS. Run the following command to confirm:

### mvn -version
Apache Maven 3.5.4 (138edd61fd100ec65BMWe46a2d307c43b76940a5d7d; 2018-07-12T07:58:13Z)
Maven home: /opt/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.11.1.el7.x86_64", arch: "amd64", family: "unix

Congratulation’s! You have successfully install and configured Apache Maven on your Ubuntu 18.04 server. Thanks for using this tutorial installing Apache Maven on Ubuntu 18.04 LTS (Bionic Beaver) system.

The Tags:

Leave a Comment

Comments are closed.