Tutorials

Install Apache Maven on Ubuntu 18.04: Stable or Latest Version

Java developers use project management tools to automate building their applications. Apache Maven is an open source tool used to manage compilation, testing, and packaging. It uses an XML configuration file called a Project Object Model (POM) to control dependencies.

This tutorial will show you how to install Apache Maven on Ubuntu 18.04. We will cover a simple install using the package manager, and a manual install to get the latest release.

Method 1: Install Apache Maven with apt (Quick Setup)

Installing Maven using the Ubuntu software sources is the fastest method. The version in the official repository is stable, though it might be older than the latest release.

Update your software package index:

bashsudo apt update

Install Maven by running:

bashsudo apt install maven

Confirm that the installation was successful by checking the version:

bashmvn -version

The output will show the installed version number and the path to the Java installation on your system.

Method 2: Install the Latest Version of Apache Maven

If you need the latest features, you can download the package archive from the official website.

First, ensure you have Java installed. You can install OpenJDK with this command:

bashsudo apt install default-jdk

Next, download the Maven package archive to the temporary folder:

bashwget https://archive.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz -P /tmp

Extract the archive files into the application directory:

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

To update versions easily in the future, create a symbolic link:

bashsudo ln -s /opt/apache-maven-3.6.0 /opt/maven

Configure System Environment Settings

You must set system variables so your shell can find the Maven commands.

Create a new setup script file:

bashsudo nano /etc/profile.d/maven.sh

Paste these lines into the file:

bashexport JAVA_HOME=/usr/lib/jvm/default-javaexport M2_HOME=/opt/mavenexport MAVEN_HOME=/opt/mavenexport PATH=${M2_HOME}/bin:${PATH}

Save the file. Make the script executable:

bashsudo chmod +x /etc/profile.d/maven.sh

Load the environment settings into your active session:

bashsource /etc/profile.d/maven.sh

Verify that the manual installation works:

bashmvn -version

The output will confirm the version, showing that the configuration is complete.

You have installed the build tool on your system. Using the package manager is convenient for quick setups, while the manual installation is best if your project requires a specific release. Leave a comment below if you run into any path configuration issues.

Cyber Defence

Recent Posts

Install Samba on Ubuntu 18.04: Configure Shares and User Access

Samba is a free, open-source implementation of the SMB/CIFS network protocol that lets Linux servers share…

16 hours ago

Set Up an OpenVPN Server on Ubuntu 18.04 with EasyRSA and UFW

Running your own VPN gives you full control over your traffic, privacy, and connection security. It encrypts…

16 hours ago

Install IntelliJ IDEA on Ubuntu 18.04 via Snap: Setup Guide

IntelliJ IDEA is a full-featured IDE for JVM and Android development made by JetBrains. It includes…

17 hours ago

Install Steam on Ubuntu 18.04: Multiverse Setup and First Run

Steam is a cross-platform digital distribution platform by Valve Corporation that gives you access to thousands…

17 hours ago

Install Redmine on Ubuntu 18.04 with MySQL, Passenger, and Nginx

Redmine is one of the most popular open-source project management and issue tracking platforms. It is…

17 hours ago

Install VirtualBox on Ubuntu 18.04 from the Oracle Repository

VirtualBox is a free, open-source, cross-platform virtualization application maintained by Oracle. It lets you run multiple…

2 days ago