Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

How to install Apache Maven on CentOS 8

Apache 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. The Maven project is hosted by the Apache Software Foundation. It was formerly part of the Jakarta Project. The installation of Apache Maven is a simple process. In this article we will install APache Maven on CentOS 8

Step 1: Install JAVA

We must install Java OpenJDK on CentOS 8 before installing maven so it can work properly.

Use following command to install Java

dnf install java-11-openjdk -y

Once the installation is complete. Verify Java installation using below command:

java -version

Step 2: Download and Install Apache Maven

We are going to install current latest version of Apache maven.

First install wget package

dnf install wget -y

Then go to /usr/local/ directory and use wget command to download maven.

cd /usr/local/
wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Now Extract the compressed file and rename “apache-maven-3.6.3” directory with “maven” for ease of access.

tar -xvf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3 maven

Apache maven has been installed.

Step 3: Configure Environment for Apache Maven

In this step we will configure Apache Maven Environment so it can be used by all users on the server.

switch to /etc/profile directory and create maven.sh file using below commands.

cd /etc/profile.d/
vi maven.sh

Now paste below script content in this file

# Configuration of Apache Maven Environment Variables
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Save changes to file and exit.

Next we have to make the script file executable and load the environment variables by using following commands

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

Verify Apache Maven installation.

mvn --version

If the installation successful you will see similar output.

Finally all of the configuration of Apache Maven has been completed.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook