How to install Maven on Ubuntu 19.10 | 20.04


Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.

Based on the concept of a project object model (POM), Maven can manage a project's build, reporting, and documentation from a central piece of information.

In this tutorial, we will learn how to install Maven in Ubuntu. The steps are generic and it will work fine on any other Linux system too. There are many ways to install maven in Ubuntu.

But here we follow 2 ways

1) By apt-get install (the easy way) 

2) By manual process from gz ( little complicated)

1) By apt-get install

First, verify whether java is installed or not using command

# java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

If java is not installed, please follow the tutorial

Search Maven

# sudo apt policy maven

image1

It is it shows that we can install maven 3.6.1-1 

b) the use the command

# apt-get install maven

then verify whether maven installed or not

# mvn -v 
Apache Maven 3.6.1
Maven home: /usr/share/maven
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.3.0-51-generic", arch: "amd64", family: "unix"

2) Install maven from gz file

if there is a problem with above installation then we can install maven from zip file for the 

 a) Download gz file from here or go to URL 

select latest apache-maven gz fie go to location /usr/share/ copy or put this downloaded file here then use command

# mkdir maven
# tar -xvzf apache-maven-3.6.3-bin.tar.gz # cd apache-maven-3.6.3 # pwd /usr/share/maven/apache-maven-3.6.3

copy this path. it is required to set an environment variable for maven in /etc/profile open the /etc/environment

# nano /etc/profile

put this 2 statement at the end of the file

export MAVEN_HOME=/usr/share/maven/apache-maven-3.6.3/
export PATH=$MAVEN_HOME/bin:$PATH

save the file. To get immediate effect use the following command

# source etc/profile

to check maven installed or not

# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/share/maven/apache-maven-3.6.3 Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "5.3.0-51-generic", arch: "amd64", family: "unix"

you will see the maven installed in our Ubuntu machine.

b) using wget command

Go to location /usr/share/ copy or put this downloaded file here then use command

# mkdir maven 
 

then

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

then use

# tar -xvzf apache-maven-3.6.3-bin.tar.gz
# cd apache-maven-3.6.3 # pwd /usr/share/maven/apache-maven-3.6.3

copy this path. it is required to set the environment variable for maven in /etc/profile

open the /etc/profile
# nano /etc/profile

put this 2 statement at the end of the file

export MAVEN_HOME=/usr/share/maven/apache-maven-3.6.3/
export PATH=$MAVEN_HOME/bin:$PATH

save file. to get immediate effect use the following command

# source etc/profile

then

# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/share/maven/apache-maven-3.6.3 Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "linux", version: "5.3.0-51-generic", arch: "amd64", family: "unix"

you will see the maven installed in our Ubuntu machine.

3) Remove maven 

If you want to remove maven the use,

# sudo apt-get remove maven3
or # sudo apt-get remove maven3

That's it, We successfully installed maven on the ubuntu machine !!!