How to Install Maven on Ubuntu 18.04

How to Install Maven on Ubuntu 18.04

Apache Maven is a free and open source project management tool, based on the Project Object Model. Maven contains XML files also referred to as pom.xml which includes configuration details, project dependencies, and other data. That’s a great tool for powering up your VPS project!

Apache Maven can help to manage projects and is most popular with Java.

There are many benefits of using Apache Maven, some of which are:

  • With Maven, you can have better dependency management.
  • It does not store third-party libraries and is easy to manage
  • Occupies less space for the project
  • All configuration is centralized in a single XML file
  • Maven can create reports showcasing the dependencies used in projects
  • Facilitates better debugging
  • Provides better collaboration. The project can use one standardized jar version
  • Reduces multiple dependencies and eliminates duplicates
  • Easy to test and deploy
  • Provides a standardized project structure
  • Provides detailed analysis about project dependencies, createS a report and highlightS missing dependencies
  • Easy to manage upgrades
  • Facilitates built and unified packaging for deployment

Maven makes it easier to manage various tasks, thus it’s smart to utilize it.

How to Install Maven on Ubuntu 18.04

To install Maven 3.3 or above you need to have JDK 1.7 or above installed.

Maven can be installed in two ways:

  1. Apache Maven can be installed on Ubuntu from the Official website
  2. Apache Maven can be installed using Apt

Before installing java, you can update the package index for Ubuntu by using:

sudo apt update

Remember, first you need to access your VPS using SSH. If you’re having trouble, check out our PuTTY tutorial!

First Method – Install Maven on Ubuntu Using the Official Website

First, let’s see how to install Maven on Ubuntu from the Official website.

Java Installation

You can install the default Open JDK package for Ubuntu by using:

apt-get update
sudo apt install default-jdk

This might take a few minutes. Once this is complete, you can verify the Java installation by using:

java -version

This will show the installed Java version.

Apache Maven Download

You can check the Maven official page to check the latest Maven version and download it using the wget command. You can download it to the /tmp directory, as shown below:

wget -P /tmp

The file will be downloaded as a .tar.gz file. You can extract it to the /opt directory by using the command:

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

Setup the Environment for Maven

To ensure Maven is working properly, you need to configure a few environment variables, including JAVA_HOME, M3_HOME, MAVEN_HOME, and PATH.

To make this change create a file named inside /etc/profile.d/ directory.

sudo vi /etc/profile.d/

The configuration below needs to be added to this newly created file.

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

Save this file by hitting escape and then typing in :wq and provide the required privileges to the file using the command below:

sudo chmod +x /etc/profile.d/

Keep in mind, that this command only configures the environment variables. To refresh and load it, use the command:

source /etc/profile.d/

Second Method – Install Apache Maven on Ubuntu 18.04 Using Apt

This is a simpler way to install Maven in Ubuntu since the official Ubuntu repositories contain Maven packages by default. However, keep in mind, that it may not be the latest Maven version.

As mentioned in the method above, you need to install Open JDK package to ensure everything runs properly.

Start by updating the package index by using:

sudo apt-get update

Next, you can install Maven using the command below:

sudo apt-get -y install maven

By default, it will be installed in /usr/share/maven and /etc/maven locations.

You can verify Maven installation by using the command below (works with both installation methods):

mvn -version

This will show the installed Apache Maven version.


Now you can start using Maven in your Ubuntu machine. You can test this by running an existing Maven project pom.xml file.

Maven certainly has several benefits when it comes to project management. You can use one of the two methods above to install Maven on Ubuntu 18.04.

The author

Edward S.

Edward is a Content Editor with years of experience in IT as a writer, marketer, and Linux enthusiast. Edward's goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.