Installing Java in centos

Install OpenJDK 8

    To install OpenJDK 8 JRE using yum, run this command:

  • sudo yum install java-1.8.0-openjdk

Install Oracle Java 9 JRE

  •  In order to install Oracle Java 9 JRE, you wil need to go to the Oracle Java 9 JRE Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm package. Substitute the copied download link in place of the highlighted part of the wget command.
  •  Change to your home directory and download the Oracle Java 9 JRE RPM with these commands:
  • cd ~

  • wget –no-cookies –no-check-certificate –header “Cookie:; oraclelicense=accept-securebackup-cookie” http://link_copied_from_site

  • Install With below command

           sudo yum localinstall jre-9.0.4_linux_x64_bin.rpm

    Set Default Java

  • If you installed multiple versions of Java, you may want to set one as your default (i.e. the one that will run when a user runs the java command). Additionally, some applications require certain environment variables to be set to locate which installation of Java to use. This section will show you how to do this.
  • By the way, to check the version of your default Java, run this command: 

    java -version

    Using Environment Variables

  • Many Java applications use the JAVA_HOME or JRE_HOME environment variables to determine which javaexecutable to use.

        For example, if you installed Java to /usr/java/jdk1.8.0_161/jre/bin (i.e. java executable is located at /usr/java/jdk1.8.0_161/jre/bin/java), you could set your JAVA_HOME environment variable in a bash shell or script like so:   export JAVA_HOME=/usr/java/jdk1.8.0_161/jre

  • If you want JAVA_HOME to be set for every user on the system by default, add the previous line to the /etc/environment file. An easy way to append it to the file is to run this command:
  • sudo sh -c “echo export JAVA_HOME=/usr/java/jdk1.8.0_161/jre >> /etc/environment”


Leave a Reply

Be the First to Comment!

Notify of

Leave a Comment

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