How To Install Maven On Ubuntu
How To Install Maven On Ubuntu
Introduction
Apache Maven is an open-source project management tool primarily used for developing Java
applications. Maven incorporates a POM (Project Object Model) approach, which means it uses an XML
file to store information about projects, configurations, and dependencies.
This tutorial explains how to install Maven on Ubuntu 20.04, both using the official repository and the
installation file on the Maven website.
Prerequisites
mvn -version
Manually installing Maven is more complex than using the apt command but offers more flexibility when
choosing which version to install.
java -version
1. Visit the Maven download page and select the version of Maven you want to install. The latest version
is listed in the Files section, and you can access earlier versions by using the archive link in the Previous
Releases section.
We are using version 3.8.4, which is the latest version at the time of writing this article.
1. Use the Nano text editor to create and open the maven.sh script file in the /etc/profile.d/ directory:
export JAVA_HOME=/usr/lib/jvm/default-java
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
5. Execute the maven.sh script file with the source command to set up the new environment variables:
source /etc/profile.d/maven.sh
mvn -version
Conclusion
After reading this tutorial, you should have a copy of Maven installed on your Ubuntu system and ready
to use.
If you are interested in trying Maven on a different Linux distribution, have a look at our guides
on installing Maven on Debian 9 and installing Maven on CentOS 7. For Windows users, refer to our
guide on installing Maven on Windows.