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.
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
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
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
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 JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-18.104.22.168.b04-0.el7_6.x86_64/jre/ :~# 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
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 :~#
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-22.214.171.124.b04-0.el7_6.x86_64/jre 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.