Install Apache Maven with Oracle Java on Ubuntu 16.04 / 17.10 / 18.04

This brief tutorial shows students and new users how to install Apache Maven with Oracle JAVA 8 on Ubuntu 16.04 / 17.10 or 18.04 LTS…

For those who don’t know about Apache Maven, here’s a brief description:

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can help you manage an entire project’s build process, including storing documents, reporting and more…

For more about Apache Maven, please check its homepage….

This post also shows you how to install Maven with the official Oracle JAVA 8 support… Maven works with OpenJava… but may work better with Oracle Java…

When you’re ready to install Maven, follow the steps below:

Step 1: Install Oracle JAVA 8

To support Maven, make sure to have Java installed… To do that, run the commands below… The easiest way to install Oracle Java JDK 8 on Ubuntu is via a third party PPA… To add that PPA, run the commands below…

sudo add-apt-repository ppa:webupd8team/java

After running the commands above, you should see a prompt to accept the PPA key onto Ubuntu… accept and continue

Now that the PPA repository has been added to Ubuntu, run the commands below to download Oracle Java 8 installer…. the installer should install the latest Java JDK 8 on your Ubuntu machines.

sudo apt update
sudo apt install oracle-java8-installer

When you run the commands above you’ll be prompted to access the license terms of the software… accept and continue..

oracle java 9

Set Oracle JDK8 as default, to do that, install the oracle-java8-set-default package. This will automatically set the JAVA env variable.

sudo apt install oracle-java8-set-default

Now that JAVA is installed, run the commands below to set its home directory….

sudo nano /etc/environment

Then copy and paste the hightlighted line below and save the file…

export JAVA_HOME

After that run the commands below…

source /etc/environment

When you run echo $JAVA_HOME  you should now see Java home directory…

Step 2: Downlaod and Install Apache Maven

After instaling Java, run the commands below to download Maven archive….

cd /tmp && wget

Then run the commands below to extract the downloaded archive…


Next, move the extracted folder to the /opt directory

sudo mv apache-maven-3.5.4 /opt/apache-maven-3.5.4

Finally, open your environment again and add Maven path..  PATH=/opt/apache-maven-3.5.4/bin:$PATH

sudo nano /etc/environment

Then add a new highlighted line below into the file and save…

export JAVA_HOME
export PATH=/opt/apache-maven-3.5.4/bin:$PATH

Finally run the commands below to complete…

source /etc/environment

You’re done… To varify if Maven is installed, run the commands below…

mvn --version

You should see something like this…

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T13:33:14-05:00)
Maven home: /opt/apache-maven-3.5.4
Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-23-generic", arch: "amd64", family: "unix"


You may also like the post below:

Install Opensource Real Estate CMS on Ubuntu 16.04 / 17.10 / 18.04 with Apache2, MariaDB and PHP 7.2