35.2 C
Senior Writer and partner

Install Apache Maven on CentOS 7

The development of Java is constant today. That’s why many people are increasingly interested in learning tools that make their work easier. So, in this sense, today you will learn to install Apache Maven in CentOS 7 as a mechanism to facilitate the deployment of applications.

Apache Maven

Maven is an open source tool that allows you to manage projects made in Java. It belongs to the Apache Foundation, which gives us a guarantee of quality and stability. One of the main achievements of Maven is the unification of criteria at the time of verifying the .JAR files generated. Moreover, it is possible to share JARs across several projects.

So, some of the Maven’s goals are as follows:

  • Making the build process easy.
  • Providing a uniform build system, quality project information, and guidelines for best practices development.
  • Allowing transparent migration to new features.

So, let us start to install Apache Maven.

1. Update the system

- Advertisement -

The first step is to have the system updated. That is to say that all the packages of the system are to their last version.

:~$ su
:~# yum update

1.- Upgrade CentOS 7
1.- Upgrade CentOS 7

This way, you will have a more stable system thanks to the security patches installed. It is also advisable to improve the robustness of some programs that could generate a security problem.

2.- Install Java on CentOS 7

Maven requires Java to work. Although it also requires the latest version of it, so we will be able to use the OpenJDK that comes in CentOS 7 refuels.

For that, in a terminal, run the following:

:~# yum install java-1.8.0-openjdk-devel

2.- Install Java on CentOS
2.- Install Java on CentOS

To be sure everything went well, you can check the Java version.

:~# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

Now it is necessary to define the JAVA_HOME variable in our system.

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

Now we can install Apache Maven.

3.- Install Apache Maven on CentOS 7

To do this, let’s download it from the project repositories. At the time of writing this post, the current version is 3.6.1.

:~# cd /tmp/
:~# wget http://www-us.apache.org/dist/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz

3.- Download and install Apache Maven
3.- Download and install Apache Maven

After that, decompress it.

:~# tar -zxvf apache-maven-3.6.1-bin.tar.gz

Then, move it to the /opt/ directory and change the owner.

:~# mv apache-maven-3.6.1 /opt/
:~# chown -R root:root /opt/apache-maven-3.6.1/

After this, it is recommended to make a symbolic link to the Maven directory. This is to avoid problems with the Maven version.

:~# ln -s /opt/apache-maven-3.6.1 /opt/apache-maven

And add it to the environment variable.

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

Then, we can verify Maven’s version.

:~# mvn --version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T15:00:29-04:00)
Maven home: /opt/apache-maven
Java version: 1.8.0_212, 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-957.12.1.el7.x86_64", arch: "amd64", family: "unix"

So, Apache Maven is correctly installed.


Installing Maven on CentOS 7 is not difficult however, it is a tool widely used by Java developers. So, because of its great project management capabilities, Apache Maven has earned its place of honor in Java programming.

So, please share this post.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article