Hamsa K
6 min read | 2 years ago

How to Install Apache Maven on Rocky Linux

Install Apache Maven on Rocky Linux 8 /Alma Linux 8

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model,Maven can manage a project's build, reporting and documentation from a central piece of information.You can also use Maven to build and manage projects written in C#, Ruby, Scala, and other languages.

In this Article, we will show you how to install apache maven on Rocky Linux.

same steps you can follow on centos 8 and Alma Linux 8.

Also Read -> How to Install PostgreSQL on Rocky Linux

Step 1: Install Java

First you need to make sure your system is uptodate.

sudo dnf update

Apache Maven requires JDK 7 or above. Here we are going with openjdk 11.

sudo dnf install java-11-openjdk-devel

verify java version with following command.

java -version


openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Also Read -> How to Install Curl on Linux

Step 2: Download and Install Maven

The latest version, at the time of writing this guide is Apache Maven 3.8.2. 

you can download whatever latest version available.

sudo dnf install wget
wget https://downloads.apache.org/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz

extract the downloaded file and move it to /opt folder as shown  below.

sudo tar -xvzf apache-maven-3.8.2-bin.tar.gz
sudo mv apache-maven-3.8.2 /opt/maven

Also Read -> How to Install and Configure Clamav in Linux

Step 3: Setup Environment variables

set the environment variables for Maven by creating a maven.sh file under /etc/profile.d/ directory.

Note : Before that, check java installed path to set Java home directory using below command.

sudo alternatives --config java

now create new file named as maven.sh as shown below.

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

Add below content to above file

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

you have to replace  java home path if it is diffrent.

Then save and exit the file.

Now set executable permissions to the script with following command.

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

Then load the environment variables using source command.

source /etc/profile.d/maven.sh

Finally verify Apache Maven installation

mvn --version


Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /opt/maven
Java version: 11.0.12, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-305.19.1.el8_4.x86_64", arch: "amd64", family: "unix"

Now you have successfully installed Apache Maven on Rocky Linux 8 system.

Also Read -> How to Install Docker and Docker Compose on Rocky Linux

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy