loader

Install Apache Maven on Ubuntu 18.04

 

 

Java projects usually use Maven as their build automation tool. In addition to C#, Ruby, and Scala, Maven can also be used to build and manage projects. It was formerly part of the Jakarta Project, which is now hosted by the Apache Software Foundation.

 

 

 

 

My goal in this tutorial is to walk you through step-by-step the installation and configuration of Apache Maven on Ubuntu 18.04.

 

 

Prerequisites 

 

 

  • A newly deployed VPSie Ubuntu 18.04 server.

 

  • A non-root user with sudo privileges created on your server.

 

 

 

Let’s get started,

 

 

 

 

 

Step 1: Update your server

 

 

 

 

First, Install the latest version of your operating system:

 

 

sudo apt-get update -y

 

sudo apt-get upgrade -y

 

 

 

Step 2: Install Java

 

 

 

JDK 1.7 or higher is required for installing Maven 3.3 or higher. During this installation, OpenJDK will be installed, which is the default Java runtime and development environment in Ubuntu 18.04. 

 

 

 

Install OpenJDK: 

 

sudo apt-get install -y default-jdk

 

 

You can verify the Java version by : 

java -version

 
As a result, the output will be as follows: 

openjdk version "16.0.2" 2021-08-20
OpenJDK Runtime Environment (build 16.0.2+13-Ubuntu-1ubuntu0.18.04.3)
OpenJDK 64-Bit Server VM (build 16.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)

 

 

 

 

Step 3: Install Apache Maven

 

 

 

First, change your working directory to the /opt/ directory:

 

 

cd /opt/

 

 

You can visit the official website to download Apache Maven’s latest stable release:

 

sudo wget https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz

 

 

Once you have downloaded the archive, extract it:

 

sudo tar -xvzf apache-maven-3.6.0-bin.tar.gz

 

The next step is to rename the extracted directory:

 

sudo mv apache-maven-3.6.0 maven 

 

 

 

Step 4: Setup environment variables

 

 

 

Afterward, you will need to set up your environment variables, such as M2_HOME, JAVA_HOME and PATH. You can do this by creating a mavenenv.sh file inside of the /etc/profile.d/ directory:

 

 

 

sudo vi /etc/profile.d/mavenenv.sh

 

 

Add the following lines:

 

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

 

 

 

Save and close the file, and make it executable:

 

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

 

 

 

Now you can load the environment variables:

 

 

 

source /etc/profile.d/mavenenv.sh

 

 

 

Step 5: Verify installation

 

 

 

 

After all the configurations have been successful, check the Apache Maven version:

 

 

mvn --version



You will see something similar to the following:

 

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2021-08-24T18:41:47Z)
Maven home: /opt/maven
Java version: 16.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-36-generic", arch: "amd64", family: "unix"



It is a pleasure for me to congratulate you on the successful installation of Apache Maven on your Ubuntu 18.04 server.

 

 

 

 

 

That’s it!

 

 

 

 

 

The purpose of this article is to show you how to install Apache maven on Ubuntu 18.04, and we hope you now have a better understanding of how this process works.









Get the most out of learning with VPSie.com