Install Maven in CentOS 7


  1. CentOS 7

  2. Root privileges


  1. Install Java 8

  2. Download Maven

  3. Configure Maven Environment

  4. Check Maven Version

  5. Clean-up

Install Java 8

Install Java 8 on CentOS 7 using the yum command.

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

Check Version:

After the installation is complete, check the installed java version.

$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

For more read this: Install Java 8 on CentOS 7

Download Maven:

Download Apache maven from its official website or use following command to download Apache Maven 3.6.0

$ cd /opt$ sudo wget

Now extract downloaded archive using following command.

$ sudo tar xzf apache-maven-3.6.0-bin.tar.gz$ sudo ln -s apache-maven-3.6.0 maven

Configure Maven Environment:

We will define some environment variables that are needed by Apache Maven.

Step 1: Now set the environments variables by creating new file /etc/profile.d/

Step 2: Add the following configuration in ‘’ configuration file.

export M2_HOME=/opt/mavenexport PATH=${M2_HOME}/bin:${PATH}

save and exit.

Step 3: Apply the configuration by running the ‘source’ command.

$ source /etc/profile.d/

Check Maven Version:

Apache Maven has been successfully configured on your system. Use the following command to check the version of installed Maven on your system.

$ mvn --version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z)
Maven home: /opt/maven
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.3.2.el7.x86_64", arch: "amd64", family: "unix"


Finally, remove the downloaded archive file from the system to free disk space.

$ sudo rm -f /opt/apache-maven-3.6.0-bin.tar.gz