# installing the java jdk via .tar.gz from java.oracle.com to a RHEL / CentOS / Oracle Linux environment – similar on Debian / Ubuntu
You have two download options for Redhat and clones for Oracle’s JDK. You can download RPM’s and use the RHEL rpm command to install the Java RPMs – or you can download a java-version.tar.gz based file – which is a combination of tar and gzip.
This blog addresses the .tar.gz installation.
Why choose this installation? In my mind it gives you more control allows a higher level of customization – location management especially. Read on.
So if you downloaded jdk-8u181-linux-x64.tar.gz here is how you can install it.
cd /root/Downloads cp -p jdk-8u181-linux-x64.tar.gz /opt cd /opt tar xvzf jdk-8u181-linux-x64.tar.gz mv jdk1.8.0_181 jdk8 # after the unzip you don't need the gzip anymore rm jdk-8u181-linux-x64.tar.gz # are there any other version of java installed that uses "alternatives"? A previous RPM install automatically adds to "alternatives" # what is "alternatives" - manages multiple versions of a software image - use "man alternatives" for more info. There is also a update-alternatives command similar on Debian / Ubuntu. alternatives --config java # install the java version you just installed into "alternatives" /opt/jdk - by doing an alternatives --install as below # (debian is something like update-alternatives) alternatives --install /usr/bin/java java /opt/jdk8/bin/java 1 # now using the config option on alternates - make this the preferred version [root@x360 ~]# alternatives --config java There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.181-2.6.14.8.0.1.el7_5.x86_64/jre/bin/java) * 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/bin/java) + 3 /opt/jdk8/bin/java Enter to keep the current selection[+], or type selection number: 3 [root@x360 ~]# java -version # then in the hadoop user (or whatever user) add the following to your /home/hadoop/.bash_profile # setting up java with java_home and path export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::") export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin # source ~/.bash_profile # to check what you have done... [hadoop@x360 ~]$ echo $JAVA_HOME /opt/jdk8 use "alternatives" command to show which installed version of java is being used - RHEL and clone compatible command
alternatives --config java [hadoop@single-node sbin]$ alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number: