How to Install Apache Maven on Ubuntu 18.04 Bionic Beaver

Install Apache Maven on Ubuntu 18.04

In this article, we will have explained the necessary steps to install and configure Apache Maven on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Apache Maven is 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. With Maven you can easily store documents, generate reports and documentation from a central piece of information.

Install Apache Maven on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Java.

Install the Java package by typing:

sudo apt install default-jdk

Verify the Java installation:

java -version

Step 3. Install Apache Maven.

  • Install Maven from the official Ubuntu repository:

So currently installed is version 3.6.1. Note that the latest available version of Apache Maven is currently 3.6.1 and it is recommended version for all users. To proceed with the installation, run the following command:

apt install maven

After the installation is complete, you can verify whether Maven is successfully installed on your Ubuntu:

mvn --version
  • Install Maven from the official source:

Download the latest stable version of Maven or use the below command to download the Apache Maven v3.6.1 using the terminal:

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

We will create a symbolic link maven which will point to the Maven installation directory:

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

Then, set the necessary environment variables by creating new file with the following content:

sudo nano /etc/profile.d/
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Make the script executable by typing:

sudo chmod +x /etc/profile.d/

Finally load the environment variables using the following command:

source /etc/profile.d/

Check whether the Apache Maven has been successfully configured on your system using the below command:

mvn -version

That’s all you need to do to install Apache Maven on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.