How to install Apache Maven on Ubuntu 20.04 LTS.

Apache Maven is a Free & open source build automation tool used primarily for Java projects. It is used for building, testing, source control management, running a web server & generating Eclipse project files. Maven also be used to build and manage projects written in C#, Ruby, Scala, and other languages.

Install Apache Maven on Ubuntu

Update the system.

apt-get update 

Install Java.

apt-get install default-jdk

Check Java version.

java -version

Here is the command output.

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

Install Apache Maven from Source.

Go to opt directory.

cd /opt
Download the Apache Maven.
wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Extract the downloaded file.

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

Change the name of extracted directory.

mv apache-maven-3.6.3 apachemaven

Set the Environment Variable.

Create a new file name. To setup environment variable to define the Java and Apache Maven path.

vim /etc/profile.d/apachemaven.sh

Add the following lines:

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

Give the execution permission:

chmod +x /etc/profile.d/apachemaven.sh

Activate the environment variable

source /etc/profile.d/apachemaven.sh

Check Apache Maven version.

mvn -version

Here is the command output.

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apachemaven
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-59-generic", arch: "amd64", family: "unix"

Install Apache Maven From APT

apt-get install maven 

Check Apache Maven version.

mvn -version

 

Leave a Reply