Install & Configure JRE, JDK, Maven, Gradle on RHEL and CentOS - chaitanyavangalapudi/devops-scripts GitHub Wiki

In this article we will discuss on installing OpenJDK only, not Oracle one.

Installation of Java8

Make sure you login to the development of Jenkins box as root and run following commands. You can also run as user with sudo privileges (add sudo before the yum command)

Install OpenJDK 8 JDK

You can install OpenJDK using yum by typing the following command on Development and Jenkins machine:

sudo yum install java-1.8.0-openjdk-devel

After this export JAVA_HOME environment variable by adding below lines to your /etc/profile or user specific .bash_profile file.

export JAVA_HOME=/usr/java/jdk1.8.0_161
export PATH=$PATH:$JAVA_HOME/bin

Install OpenJDK 8 JRE

You can install OpenJDK 8 JRE using yum by typing the following command on deployment machines:

sudo yum install java-1.8.0-openjdk

References:


Installation and Configuration of Apache Maven

Apache Maven is a open source software project management and build automation tool, that is based on the conception of a project object model (POM), which is primarily used for deploying Java-based applications. Maven 3.3+ requires JDK 1.7 or above to execute. Install JDK following the procedure discussed above.

Install Apache Maven

Go to the official Apache Maven download page and copy the link to latest version of maven tar file and download using wget command to $USER_HOME (home directory). In our case we will install Maven 3.6.

  • Download Maven 3.6 binary using below command
wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz

OR

wget http://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
  • Extract the downloaded archive file, and create softlink.
tar -xvf apache-maven-3.6.0-bin.tar.gz -C /opt
ln -s /opt/apache-maven-3.6.0 /opt/maven

To upgrade your Maven installation, simply unpack the newer version and change the symlink to point to it.

  • Configure Apache Maven Environment

We need to configure the environment variables for Apache Maven by creating script file ‘maven.sh’ in the ‘/etc/profile.d’ directory.

vi /etc/profile.d/maven.sh

Add the following configuration in ‘maven.sh’ configuration file.

# Apache Maven Environment Variables
export M2_HOME=/opt/maven
export PATH=${PATH}:${M2_HOME}/bin
  • Now make the ‘maven.sh’ configuration file executable and then load the configuration by running the ‘source’ command.
chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
  • Check Apache Maven Version To verify Apache Maven installation, run the following maven command.

mvn --version

References: