Hamsa K
5 min read | 3 years ago

How to Install Apache Maven on Ubuntu 20 04

Install Apache Maven on Ubuntu 20.04

Apache Maven is a software project management and comprehension tool.it is used to manage Java projects and manage a project’s build, reporting, and documentation.Maven relies on the Project Object Model (POM) to describe the project, as well as its dependencies for later deployment.

In this article we will show you how to install Apache Maven on Ubuntu 20.04 Lts system.

Also Read -> How to Install CouchDB on Ubuntu 20 04

Install Java

First we need to make sure all packages are uptodate using apt.

sudo apt update

Apache Maven required to install Java with the following command.

sudo apt install default-jdk

check java version 

java --version


openjdk 2020-11-04
OpenJDK Runtime Environment (build
OpenJDK 64-Bit Server VM (build, mixed mode, sharing)

Also Read -> How to Install Apache Tomcat 9 on Ubuntu 20 04

Install Apache Maven using ubuntu Repo

sudo apt install maven 

verify maven version as below.

mvn -version

Install Apache Maven from source

you can download Apache maven from its official website or download it using following command.

root@ubuntu20:~# cd /opt
root@ubuntu20:/opt# wget https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Also Read -> How to Install Atom Text Editor on Ubuntu 20 04

now extract the downloaded archive and rename it.

root@ubuntu20:/opt# tar -xvzf apache-maven-3.6.3-bin.tar.gz
root@ubuntu20:/opt# mv apache-maven-3.6.3 maven

Setup Environment Variables

Now we need to make Apache Maven available from anywhere on the prompt, a new file has to be created within the bash profile.create a new file as maven.sh and setup Maven environment variables.

nano /etc/profile.d/maven.sh

Add below content to above file 

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

save the file and exit.

Then load the new environment variables using below command.

source /etc/profile.d/maven.sh

Next, verify the Maven version with the following command

mvn -version

sample output:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version:, 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-60-generic", arch: "amd64", family: "unix"

That's it. Now you learned how to install Apache Maven using different methods on Ubuntu 20.04 system.

Also Read -> How to Install Zoom on Ubuntu 20.04

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy