Sunday, April 21, 2024
HomeCentosHow to Install Apache Maven on CentOS 8 and RHEL 8

How to Install Apache Maven on CentOS 8 and RHEL 8

Apache Maven is a free and open source tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby and other languages. This project is hosted by the Apache Software Foundation. It was formerly part of the Jakarta Project. In this article you will learn what how to install Apache Maven on CentOS and RHEL 8.

Prerequisites

The instructions assume that you are logged in as root user and JAVA is installed on machine because JAVA is necessary for it.

Step 1 Install JAVA

As JAVA is Necessary for Maven so, we need to install Java OpenJDK on CentOS 8 and RHEL 8 using below command.

dnf install java-11-openjdk -y

Once the installation done. You can verify Java installation using below command.

java -version 


Step 2: Download and Install Apache Maven

You can download latest binary release from maven download page

Install wget tool

dnf install wget -y

Then go to /usr/local/ directory and 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 to “maven”

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

Finally it has been installed and you can start using it. but, its environment is not configured but we will do that in next step.

Step 3: Configure Environment for Apache Maven

Now we are going to setup Apache Maven Environment so all users on the machine can use it.

Go to /etc/profile/ directory and create maven.sh file.

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

Now paste below script content in this file

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

Save changes to file and exit.

Make the script file executable and load the environment variable using below commands.

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

Finally verify Maven installation and its version using below command.

mvn --version

If everything is successful you will see below output.

That’s it. The latest version of Maven is now installed on your CentOS system.

You can also learn, how to monitor your Linux machine using SAR commands by clicking here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


spot_img

Most Popular