Install the Latest Apache Maven with OpenJDK on Ubuntu 16.04 | 18.04 | 18.10

Apache Maven comes with the default Ubuntu repositories… so all it takes is to run the apt install maven commands to get it… However, when you install Apache Maven from Ubuntu repositories, you’re not getting the latest version of Maven…

If you want to install the latest, you will have to manually download and install the latest package from its download page… and this brief tutorial is going to show students and new users how to do that on Ubuntu 16.04 | 18.04 and 18.10 systems…

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….There are two options (maybe more) available to getting Apache Maven on Ubuntu… They are installing from Ubuntu default repositories using the apt install maven commands, and/or downloading the package the archive package from its website…

Below are the two options of installing Apache Maven

Option #1: Install Apache Maven on Ubuntu with Apt-get

To install a stable and older version of Apache Maven on Ubuntu, run the commands below… This command will install OpenJDK along with Maven stable version…

sudo apt update
sudo apt install maven

The commands above update Ubuntu and install Apache Maven along with all dependencies, including OpenJDK… This is the fastest and easiest if you don’t care about getting the latest version of Apache Maven…

To verify the installed version, run the commands below

mvn --version

You should see something similar to the content below:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.2, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"

If you want to install the latest version, continue below to option #2

Option #2: Download and Install Maven

The second option is to manually install OpenJDK and Maven packages… To do that, follow the steps below:

First install OpenJDK on Ubuntu… to do that, run the commands below:

sudo apt update
sudo apt install default-jdk

That should install OpenJDK on Ubuntu and configure it to work on Ubuntu system….

Next, go and download Apache Maven latest from its download page…

At the time of writing this post, the latest version of Apache Maven is 3.5.4…. Make sure to check the Maven download page to see if a newer version is available for you to download… If there are, select those and download instead….

Run the commands below to download version 3.5.4

cd /tmp

Next, run the commands below to extract the downloaded package to the /opt directory…

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

If you want to have separate versions and update as they become available, create a symbolic link to the version folder…

sudo ln -s /opt/apache-maven-3.5.4 /opt/maven

When the next version is released… all you have to do is update the symbolic link to reference the new release folder by running the command above and updating the release number in the folder name….

Setup Maven Environment Variables

After downloading and extracting Maven package, go and setup its environment variables… To do that, run the commands below:

sudo nano /etc/profile.d/

Then copy and pastes the lines below and save into the file…

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

Finally, run the commands below to update and load the changes…

sudo chmod +x /etc/profile.d/
source /etc/profile.d/

That’s it!

Now run the commands below to check the version number…

mvn --version

You should see the content below…

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


You’ve learn how to install Apache Maven with OpenJDK using the two methods above… Either methods should work… however, if you want more control over the version you want to install, then use option #2

You may also like the post below:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.