How to Install Apache Maven on Ubuntu 20.04

How to Install Apache Maven on Ubuntu 20.04

Apache Maven is a popular project management and automation tool mainly used for Java projects. Maven can simply your software build processes. Apache Maven makes software build processes more simple. It encourages the best development operations and provide quality information about your project. Maven uses POM and Plugins to build a project. Maven reduces the developer time to build a project.

In this tutorial we are going to learn how to install apache maven on ubuntu 20.04.

We can install Apache Maven with ubuntu apt package manager and Apache Maven official source. Let start the Apache Maven installation.

Install Apache Maven with apt:

Installing Apache Maven with apt package manager is the easiest method to install Apache Maven on ubuntu 20.04. This will install the stable version of Apache Maven.

Before installing Apache Maven update the packages.

sudo apt update

To install the Apache Maven run the command below.

sudo apt install maven

To verify the installation run the command below.

mvn -version
Output

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

Download and Install the latest Apache Maven from Source:

If you want to install the latest version of Apache Maven on ubuntu 20.04 then choose this method. Let’s start Apache Maven installation.

Install OpenJDK:

Apache Maven needs Java to be installed on ubuntu 20.04. To install OpenJDK on ubuntu 20.04 run the command below.

Before installing OpenJDK update the packages.

sudo apt update
sudo apt install default-jdk

To verify the Java installation run the command below.

java --version
Output

openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment (build 11.0.9+11-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.9+11-post-Debian-1deb10u1, mixed mode, sharing)

We have successfully installed OpenJDK 11 on Ubuntu 20.04 now move to the Apache Maven installation.

Download Apache Maven from Source:

To install the Apache Maven on ubuntu 20.04 we have to download the Apache Maven file from official source. To download the Apache Maven file run the command below.

cd /tmp
wget https://www-us.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

Extract Apache Maven:

After downloading the Apache Maven file now extract the Apache Maven file to opt directory.

sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

To maintain the Apache Maven different versions and future updates create a symlink to the Apache Maven installation folder.

sudo ln -s /opt/apache-maven-3.5.4 /opt/maven

Configure Environment Variables:

To configure the Apache Maven environment variables create a file named maven.sh in the /etc/profile.d/ folder.

sudo nano /etc/profile.d/maven.sh

After opening the maven.sh file then copy and paste the following configurations to the maven.sh file then save and close the file.

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

After creating maven.sh file now give the required permissions for execution.

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

To activate the Apache Maven environment variables run the command below.

source /etc/profile.d/maven.sh

Now verify the Apache Maven installation.

mvn -version
Output

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

That’s all we have successfully installed Apache Maven on Ubuntu 20.04.

Conclusion:

In this tutorial we have learned how to install Apache Maven on Ubuntu 20.04 from two methods. Hope this tutorial will helps.

Next Article: How to Install and Configure Apache Cassandra on Ubuntu 20.04

Leave a Reply

Post your comments here

You May Also Like