Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Tuesday, 25 December 2018

Install Apache Maven 3.6 on CentOS 7

Install-Apache-Maven-3-on-CentOS-7Apache Maven is a build automation and project management tool. Maven primarily build for Java projects, but due to its plugin based architecture, it can be used for C#, Ruby, C, C++, etc projects. Apache Maven projects are build around Project Object Model (POM) and uses an XML file (pom.xml) to describe its software project configurations.

In this article, we will install Apache Maven 3.6 (latest) on CentOS 7 server. Apache Maven 3.6 requires Java Development Kit (JDK) 1.7 or above. Therefore, first we will install OpenJDK 1.8 then we will install Apache Maven 3.6.

 

System Specification:

We have a CentOS 7 virtual machine with following specification:

Hostname appserver-01.example.com
IP Address 192.168.116.130/24
Operating System CentOS 7.6

 

Install Java Development Kit (openJDK):

Connect to appserver-01.example.com using ssh.

Apache Maven 3.6 requires Java Development Kit (JDK) 1.7 or above.

We have JDK 1.8 available in CentOS yum repository. Therefore, install it using yum command.

[root@appserver-01 ~]# yum install -y java-1.8.0-openjdk-devel ... Installed: java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 Dependency Installed: java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6 Complete!

If you already have another version of Java installed, then use alternatives command to set active java command.

[root@appserver-01 ~]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- + 1 /usr/java/jdk-11.0.1/bin/java * 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number: 2 [root@appserver-01 ~]#

Repeat the above step for javac and jar commands.

Set JAVA_HOME environment variable.

[root@appserver-01 ~]# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64" >> /etc/profile

Check version of active java command.

[root@appserver-01 ~]# 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)

OpenJDK 1.8 has been installed and configured on our CentOS 7 server.

 

Install Apache Maven 3.6:

Download Apache Maven 3.6 from https://maven.apache.org/. It is the latest version at the time of this write-up.

[root@appserver-01 ~]# wget https://www-eu.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz --2018-12-25 18:26:42-- https://www-eu.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz Resolving www-eu.apache.org (www-eu.apache.org)... 95.216.24.32, 2a01:4f9:2a:185f::2 Connecting to www-eu.apache.org (www-eu.apache.org)|95.216.24.32|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 9063587 (8.6M) [application/x-gzip] Saving to: âapache-maven-3.6.0-bin.tar.gzâ 100%[======================================>] 9,063,587 271KB/s in 28s 2018-12-25 18:27:11 (317 KB/s) - âapache-maven-3.6.0-bin.tar.gzâ saved [9063587/9063587]

Extract Apache Maven tarball to /usr/lib directory.

[root@appserver-01 ~]# tar xvf apache-maven-3.6.0-bin.tar.gz -C /usr/lib/ ... apache-maven-3.6.0/lib/wagon-file-3.2.0.jar apache-maven-3.6.0/lib/maven-resolver-connector-basic-1.3.1.jar apache-maven-3.6.0/lib/maven-resolver-transport-wagon-1.3.1.jar apache-maven-3.6.0/lib/maven-slf4j-provider-3.6.0.jar apache-maven-3.6.0/lib/jansi-1.17.1.jar

Set Apache Maven environment variables.

[root@appserver-01 ~]# vi /etc/profile

Append following lines at the end of this file.

M2_HOME="/usr/lib/apache-maven-3.6.0" export M2_HOME M2="$M2_HOME/bin" MAVEN_OPTS="-Xms256m -Xmx512m" export M2 MAVEN_OPTS PATH=$M2:$PATH export PATH

Apply these changes to current user session, execute /etc/profile.

[root@appserver-01 ~]# . /etc/profile

Verify the environment variables.

[root@appserver-01 ~]# env | grep M2 M2=/usr/lib/apache-maven-3.6.0/bin M2_HOME=/usr/lib/apache-maven-3.6.0

Verify Apache Maven installation by executing mvn command.

[root@appserver-01 ~]# mvn -version Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T23:41:47+05:00) Maven home: /usr/lib/apache-maven-3.6.0 Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

Apache Maven has been successfully installed on our CentOS 7 server.

Install Apache Maven 3.6 on CentOS 7


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment