Press "Enter" to skip to content


Step 1: Update the System

To begin, let’s update the system’s package repositories and installed packages. Open the terminal and run the following command:

sudo yum update

Step 2: Install Java Development Kit (JDK)

Apache Maven on CentOS requires Java to be installed on your system. We will install the OpenJDK package, which is a free and open-source implementation of the Java Development Kit. Enter the following command in the terminal:

 yum install java-1.8.0-openjdk-devel

Step 3: Downloading Apache Maven

Next, we need to download the latest stable version of Apache Maven on CentOS. Visit the official Apache Maven website ( and locate the link to the Binary tar.gz archive. Copy the link address for the most recent release.

Back in the terminal, navigate to the directory where you want to store the Apache Maven on CentOS installation package and use the wget command to download it. Replace the link below with the copied URL:

# cd /opt
# wget
# tar zxvf apache-maven-3.9.6-bin.tar.gz

Step 4: Configuring Environment Variables

To configure the environment variables for Apache Maven, we will create a new file called in the /etc/profile.d/ directory. Run the following command:

sudo nano /etc/profile.d/

Add the following lines to the file:

cat /etc/profile.d/
export JAVA_HOME=/usr/lib/jvm/jdk-1.8.0-openjdk
export M2_HOME=/opt/apache-maven-3.9.6
export MAVEN_HOME=/opt/apache-maven-3.9.6
export PATH=${M2_HOME}/bin:${PATH}

We need to make the script executable. Execute the following command:

sudo chmod +x /etc/profile.d/

Step 5: Apply Environment Variables

To apply the newly added environment variables, either restart your system or run the following command in the terminal:

source /etc/profile.d/

To verify that Maven is correctly installed, enter the following command:

mvn -version

You should see the Maven version and other details printed on the console if the installation was successful.



您的电子邮箱地址不会被公开。 必填项已用 * 标注