Learn How To Install Apache Maven 3.5 on CentOS 7

April 19, 2020

Table of Contents

Apache Maven is a free and open source software project management tool which is widely used for deploying Java-based applications.


  • A newly deployed IT Web Services CentOS 7 x64 server instance.
  • A sudo user.
  • https://www.itweb.services/tutorials/linux-guides/how-to-update-centos-7-ubuntu-16-04-and-debian-8″>updated to the latest stable status.

Step 1: Install OpenJDK 8

Apache Maven requires Java 1.7 or greater. For this reason, you can install OpenJDK 8 as follows.

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

Having OpenJDK 8 installed, use the command below to verify the result.

java -version

If all went well, the output should be similar to this.

openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

Finally, setup the JAVA_HOME environment variable.

echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile
source /etc/profile

Step 2: Install Apache Maven 3.5

First, download and extract the Apache Maven 3.5 archive.

wget http://www-us.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
tar -zxvf apache-maven-3.5.0-bin.tar.gz

Move all Apache Maven 3.5 files to a reasonable location and change their ownership to root:root:

sudo mv ~/apache-maven-3.5.0 /opt
sudo chown -R root:root /opt/apache-maven-3.5.0

Create a version-irrelevant symbolic link pointing to the original Apache Maven 3.5 directory.

sudo ln -s /opt/apache-maven-3.5.0 /opt/apache-maven

Add the path /opt/apache-maven to the PATH environment variable.

echo 'export PATH=$PATH:/opt/apache-maven/bin' | sudo tee -a /etc/profile
source /etc/profile

Finally, use the command below to verify the installation.

mvn --version

The output should resemble the following.

Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T19:39:06Z)
Maven home: /opt/maven
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.26.2.el7.x86_64", arch: "amd64", family: "unix"

You have successfully installed Apache Maven on your CentOS 7 server instance.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!