How to Install Apache Maven on Ubuntu

This guide will show you how to install Apache Maven on Ubuntu. You will also see how to verify the install and set up a basic project for testing purposes.
About Apache Maven
Apache Maven (also known as MVN) is a build automation tool used by many Java projects.
As per Apache:
Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal, Maven deals with several areas of concern:
- Making the build process easy
- Providing a uniform build system
- Providing quality project information
- Encouraging better development practices
Let’s get started!
You can install Apache Maven on Ubuntu using the following commands:
sudo apt update
sudo apt install maven
Verify the install
In addition, you can verify the install of Apache Maven using the command:
mvn -version
For example, this command will produce output like this:
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_AU, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-37-generic", arch: "amd64", family: "unix"
Create a basic Apache Maven Project
First, navigate to the folder where you want your project to reside. Then run the following command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
You can then run the following command to package the project:
mvn package
Or, you can visit the Apache Maven project page for an excellent 5-minute guide.