How to Install Oracle Java 8 on CentOS 7 / RHEL 7
This guide will be more useful for them to set up a development environment when they especially use RHEL or CentOS.
Download Java SDK
You can either use command line or browser to download the JDK, better to use the browser, the easiest one. Visit the Oracle SDK page to download. If you still want to use the command line, use the below command.
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.tar.gz tar -zxvf jdk-8u*-linux-x64.tar.gz mv jdk1.8.*/ /usr/
Install Oracle Java 8
Once moved the java to the desired location, you must setup Java with the alternatives commands. Below command will install the Java on your system.
alternatives --install /usr/bin/java java /usr/jdk1.8.*/bin/java 2 alternatives --config java
Select the latest Java:
If your system has multiple versions of Java installed, then the above command may list you all, like below.
There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-18.104.22.168-1.b12.el7_4.x86_64/jre/bin/java) 2 /usr/jdk1.8.0_181/bin/java Enter to keep the current selection[+], or type selection number: 2
Verify the Java
Once you set up the alternatives. Check the java version installed using the following command.
java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Setup Environmental Variable
The most important part has come now, it should be set before the installation of any Java-based applications.
# export JAVA_HOME=/usr/jdk1.8.0_* # export JRE_HOME=/usr/jdk1.8.0_*/jre/
Set PATH variable too.
# export PATH=$JAVA_HOME/bin:$PATH
To set it as a permanent, place the above three commands in the “/etc/profile” (All Users) or “~/.bash_profile ” (Single User)
That’s All!. Hope this helped you. Place your valuable comments below.