8.3 C
Amsterdam
Thursday, January 21, 2021

How To Install Apache Maven on CentOS 8

Must read

Please Donate

Today, we are going to learn that how to Install Apache Maven on CentOS 8. Apache Maven is a build automation tool used frequently for java tasks. Maven also can be used to develop and manipulate projects written in c#, ruby, scala, and other languages.

Maven addresses two aspects of developing software: how software is developed, and its dependencies. Not like in advance equipment like Apache ant, it makes use of conventions for the build technique, and most effective exceptions need to be written down.

An xml document describes the software assignment being developed, its dependencies on other outside modules and additives, the build order, directories, and required plugins. It comes with pre-defined targets for performing certain nicely-defined tasks together with compilation of code and its packaging.

So, let’s move towards the installation of Apache Maven on CentOS 8.

Step 1: Install OpenJDK 8

First of all install the main requirements for the installation of Apache Maven. You can install Oracle Java on CentOS 8 or proceed with the OpenJDK. I’m starting my installation with the OpenJDK. So, install the java by running the following command.

sudo dnf -y install java-1.8.0-openjdk-devel

Make sure that the installation was successful. For this run the given command

java -version

Output:

You’ll see the output like below

[sabi@localhost ~]$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Step 2: Install Apache Maven

If you don’t have installed wget, install it by typing

sudo dnf -y install wget

Output:

[sabi@localhost ~]$ sudo dnf -y install wget
Last metadata expiration check: 6:36:15 ago on Sun 29 Mar 2020 10:50:06 PM EDT.
Package wget-1.19.5-7.el8_0.1.x86_64 is already installed.
Dependencies resolved.
Package Architecture Version Repository Size
Upgrading:
wget x86_64 1.19.5-8.el8_1.1 AppStream 735 k
Transaction Summary
Upgrade 1 Package
Total download size: 735 k
Downloading Packages:
wget-1.19.5-8.el8_1.1.x86_64.rpm 13 kB/s | 735 kB 00:54
Total 13 kB/s | 735 kB 00:55

Then go to the Apache Maven official release page to download the latest version of it. You can also donwload it by the following command

wget https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Once, the package is downloaded, extract the archive by typing the given command.

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

And then move the resultant to the /opt/maven directory

mv apache-maven-3.6.3 /opt/maven

Step 3: Setting Up Environment Variables

After installing the Apache Maven, create a new file as maven.sh under the /etc/profile.d/ directory. You can use your favorite editor.

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

And then paste the below data into the above file.

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64/
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

Note: JAVA_HOME & M2_HOME depends on JDK & Maven installation.

After it load the environment variables with the help of the given command

source /etc/profile.d/maven.sh

Step 4: Verification of Apache Maven

Verify the successful configuration of Apache Maven on CentOS 8 by checking the version of Maven using below command

mvn -version

Output:

You will see the similar output

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven
Java version: 1.8.0_232, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-80.11.2.el8_0.x86_64", arch: "amd64", family: "unix"

So, this is how you can install Apache Maven on CentOS 8.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

-

Latest article

x