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

xargs Command in Linux: Build and Execute Commands from Input

The xargs command in Linux reads items from standard input and passes them as arguments to another…

2 days ago

locate Command in Linux: Find Files Fast with a Database Search

The locate command in Linux searches for files and directories by name. It queries a pre-built database…

2 days ago

Listing Linux Services with systemctl: A Complete Guide

Most modern Linux distributions use systemd as the default service manager. Knowing how to list…

2 days ago

How to Truncate Files in Linux: Empty Files Without Deleting

Truncating a file in Linux means removing its contents while leaving the file itself in…

2 days ago

ss Command in Linux: Display Socket Statistics and Connections

The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…

3 days ago

ftp Command in Linux: Connect to Servers and Transfer Files

The ftp command in Linux connects to a remote FTP server and transfers files. FTP transmits everything…

3 days ago