How to Install Maven on Ubuntu 16.04

How to Install Maven on Ubuntu 16.04

In this tutorial, we will show you how to install Apache Maven 3 on  Ubuntu 16.04. Apache Maven is a free and open-source, software project management and comprehension tool written in Java. Based on the concept of a project object model (POM), Maven can manage an entire project’s build.

how to install maven on ubuntu 16.04

With Maven, you can easily store documents, generate reports and documentation from a central piece of information. Installing Maven on Ubuntu 16.04 is a fairly easy task if you follow the steps below carefully and should not take more than 10 minutes.

1. Login via SSH

First of all login to your Ubuntu 16.04 VPS via SSH as user root

ssh root@IP_Address -p Port_number

2. Update OS Packages

and update all installed packages to the latest version

apt-get update && apt-get upgrade

3. Check Maven Version

The installation of Apache Maven is a very simple process. It is available in the official Ubuntu 16.04 repository. You can check the exact version by executing the following command

apt-cache show maven | grep Version
Version: 3.3.9-3

4. Install Maven from the official repository

So currently installed is version 3.3.9. Note that the latest available version of Apache Maven is currently 3.5.2 and it is the recommended version for all users.

To proceed with the installation, run the following command

apt-get -y install maven

This will install the latest Maven 3 version available in the repository along with all Maven dependencies, including Java.

After the installation is complete, you can verify whether Maven is successfully installed on your Ubuntu 16.04 server, use the following command

mvn --version

The result should be similar to

Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "2.6.32-042stab127.2", arch: "amd64", family: "unix"

5. Manual Installation of Maven

As we already mentioned, 3.3.9 is not the latest version of Maven. If you want to install the latest one, you can download it from Maven’s official website. First of all, we have to install Java on the server. It is not available in the official Ubuntu 16.04 repository, so we will add the PPA repository maintained by the Webupd8 team

apt-get install software-properties-common
apt-add-repository ppa:webupd8team/java
apt-get update

6. Install Java

Next, install Java 8 with the following command

apt-get install oracle-java8-installer

To verify the installation, run

java -version

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

7. Download Latest Maven Version

Download the latest stable release Maven

wget http://ftp.wayne.edu/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.zip

Once downloaded, unpack the zip archive

unzip apache-maven-3.5.2-bin.zip

8. Configure Maven

rename the create directory to something simpler

mv apache-maven-3.5.2 maven

Set the necessary environment variables by creating new file with the following content

nano /etc/profile.d/maven.sh

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

Make sure that all paths are correct.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

Run the following command to load the environment variables

source /etc/profile.d/maven.sh

9. Verify Maven Installation on Ubuntu 16.04

And finally, verify that Maven is properly installed

mvn -version Listed below are some of the main Maven 3 features: – Simple project setup – Plugin extension points – Maven shell – Consistent usage across all projects – Model-based builds – Automatic parent versioning – Dependency management – Parallel builds and many more.

That’s it, you have successfully installed Maven on CentOS 7. For installing Maven on CentOS 7, check this tutorial – HOW TO INSTALL MAVEN ON CENTOS 7.

New guide available here: How to Install Apache Maven on Ubuntu 20.04.


How to Install Maven on Ubuntu 16.04

If you use one of our Ubuntu VPS Hosting plans, you don’t have to Install Maven on Ubuntu 16.04 yourself, you can simply ask our expert Linux admins to install Maven on your Ubuntu 16.04 VPS for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on How to Install Maven on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “How to Install Maven on Ubuntu 16.04”

  1. As much as I’m pro rage you should change to line
    apt-get update && apt-get upgrage
    to:
    apt-get update && apt-get upgrade

    Reply

Leave a Comment