How to Install Apache Maven 3.5 on CentOS 7

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


  • A newly deployed Vultr CentOS 7 x64 server instance.
  • A sudo user.
  • The server instance has been 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/profilesource /etc/profile

Step 2: Install Apache Maven 3.5

First, download and extract the Apache Maven 3.5 archive.

cdwget -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 /optsudo 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/profilesource /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/mavenJava version: 1.8.0_141, vendor: Oracle CorporationJava home: /usr/lib/jvm/java-1.8.0-openjdk- locale: en_US, platform encoding: UTF-8OS 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.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.