There is a new version of this tutorial available for Ubuntu 22.04 (Jammy Jellyfish).

How to Install Apache Maven on Ubuntu 20.04

Apache Maven is a free and open-source project management tool primarily for Java projects. It is based on POM and also used to build and manage projects written in C#, Ruby, Scala, and others. It comes with built-in objective commands that can be used to manage packages and code composition.

In this tutorial, we will show you how to install the Apache Maven project management tool on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is configured the server.

Install Java

Apache Maven is based on Java. So Java must be installed in your server. You can install the Java using the following command:

apt-get install default-jdk -y

Once the Java is installed, you can verify the installed version of Java with the following command:

java --version

You should get the following output:

openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

Install Apache Maven from Ubuntu Repository

By default, Apache Maven is available in the Ubuntu 20.04 default repository. You can install it with the following command:

apt-get install maven -y

Once the installation is completed, you can verify the Apache Maven version with the following command:

mvn -version

You should get the following output:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-29-generic", arch: "amd64", family: "unix"

Install Apache Maven from the Source

You can also install the Apache Maven from the source. First, download the latest version of Apache Maven with the following command:

wget https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvf apache-maven-3.6.3-bin.tar.gz

Next, move the extracted directory to the /opt with the following command:

mv apache-maven-3.6.3 /opt/maven

Next, create a new maven.sh and setup Maven environment variables.

nano /etc/profile.d/maven.sh

Add the following lines:

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

Save and close the file then give the execution permission and activate the environment variables with the following command:

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

Next, verify the Maven version with the following command:

mvn -version

You should get the following output:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-29-generic", arch: "amd64", family: "unix"

Conclusion

In the above guide, you learned how to install Apache Maven using different methods on Ubuntu 20.04. I hope you can now easily install your required version of Maven in your system.

Share this page:

0 Comment(s)