Install latest Java on RHEL /CentOS and Fedora

This article explain you how to install and configure Java  JDK latest version  on CentOS /RHEL servers. Here We are going to install latest Java 14 JDK on  CentOS 8  Version. Below is my CentOS Server information.

 Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-147.el8.x86_64
      Architecture: x86-64

Download Java 14  JDK   Latest Version

Download  latest  Java SE  Development Kit  8  from its official Java vendor website. Below are the steps to extract download jdk file in temporary folder in linux . You have to download the tar archived file. We downloaded the jdk file in our tmp folder. So we will go into the /tmp folder and extract there.

# cd /tmp
# wget
# tar xzf openjdk-14_linux-x64_bin.tar.gz
# mv jdk-14 /opt

Install  Java 14

Now we have got extracted folder of java (jdk1.8.0_241). Alternatives command is the best way to install java. Go to the extracted folder of java and run like below command as showing.

# cd /opt/jdk-14
# alternatives --install /usr/bin/java java /opt/jdk-14/bin/java 2/opt/jdk1.8.0_241/bin/java 2 

Now we should set  jar and javac  path

# alternatives --install /usr/bin/jar jar /opt/jdk-14/bin/jar 2

# alternatives --install /usr/bin/javac javac /opt/jdk-14/bin/javac 2

# alternatives --set jar /opt/jdk-14/bin/jar

# alternatives --set javac /opt/jdk-14/bin/javac

Set  Java Environment Variables :

After the set of javac and jre path , we will set the environment variables  in linux . So many application needs to use the JAVA_Home or JRE_HOME environment variables for java executable to use, even you can not  see java version without environment  variables set.

To set  java home variable use below command.

export JAVA_HOME=/opt/jdk-14/

To set  jre home variable use below command

export JRE_HOME=/opt/jdk-14/jre/

To set the path variables use below command

export PATH=$PATH:/opt/jdk-14/bin:/opt/jdk-14/jre/bin

Verify Installed Java Version

Now check the version of installed java on linux box through below command

# java --version
openjdk 14 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

If your java command not running after set the environment variables then add below lines  in bashrc and profile files in /etc directory.

export JRE_HOME=/opt/jdk-14/jre
 export PATH=$JAVA_HOME/bin:$PATH

Congratulations, Now we have install , run and configure java !

About Sachin Gupta

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks!