Install latest Java and set Environment

openJdk on CentOS 7 Distribution

1) Run below command to install java-8-openjdk-devel package.


sudo yum install java-1.8.0-openjdk-devel


2) Verify the installation by checking the java version.


 $ java -version
  openjdk version "1.8.0_232"
  OpenJDK Runtime Environment (build 1.8.0_232-b09)
  OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)


3) Setup Java Home and Path for all Unix users

add a new script with any name to /etc/profile.d.

for example create file with name : and add below contents to it.


export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")


or below to do it in one single step.


echo export JAVA_HOME='$(readlink -f /usr/bin/java | sed "s:/bin/java::")' | sudo tee /etc/profile.d/ > /dev/null

If you do not want to restart, you can run below command to run all the profile.d scripts.


                 source /etc/source


Note: In case if you want to set jdk as the Home , then add below instead of jre.


export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")

Written by Ramesh Metta

Leave a Reply

Your email address will not be published. Required fields are marked *