Technical: Sun\Oracle – Installing and Configuring Java in Preparation of Hadoop Install on CentOS (v6.5)

 

 

Technical: Sun\Oracle – Installing and Configuring Java in Preparation of Hadoop Install on CentOS (v6.5)

Background

Preparing to revisit install of Apache’s Hadoop install and configuration on our CentOS machines.

I know that we need Sun/Oracle’s branded Java, but that the bundled Java is the OpenJDK version.

Let us go fix that.

 

Get Java Vendor & Version

That is, let us determine our installed Java Vendor and Version Number.

Help is going to come from:

What is the Value of Java_HOME for Cent OS
http://serverfault.com/questions/50883/what-is-the-value-of-java-home-for-centos

 

Syntax:

update-alternatives --display <app-name>

 

Command:

update-alternatives --display java | egrep "link | priority"

 

Output:

update-alternatives--display--before

 

Our output reads “link currently points to /usr/lib/jvm/jre-1.7.0-openjdk/bin/java” and so it appears that we are using OpenJDK.

We know Apache will rather have us use Sun\Oracle JDK.  And, so let us go get that.

Listing of Oracle JDK version 8 (JDK 1.8)

Using a web browser, journeyed to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and here is what we see.

Java-JRE-Selections

 

 

Download JDK v8  (JDK 1.8 – Linux x86 – RPM)

Though we can download through GUI\web browser, we have chosen to download via wget.

http://stackoverflow.com/questions/10268583/how-to-automate-download-and-installation-of-java-jdk-on-linux

 

Syntax:


wget --no-check-certificate --no-cookies  --header "Cookie: oraclelicense=accept-securebackup-cookie" <url> -O <file>

 

 

Command:


wget --no-check-certificate --no-cookies  --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-i586.rpm" -O "/tmp/jdk-8-linux-i586.rpm"

 

 Output:

wget

Install Oracle / Sun Java JDK

Syntax:

sudo yum install -y <jdk-rpm>

Sample:

sudo yum install -y /tmp/jdk-8-linux-i586.rpm

 

Review Installed RPMS (Java)

Let us query rpm and make sure that our new JDK rpm is installed.

Syntax:

rpm -qa 

 

Sample:

rpm -qa | grep jdk

 

Output:

x64

rpm-qa-java

 

x32

rpm --qa -- grep jdk

 

Uninstall OpenJDK RPMs


Syntax:

sudo rpm -e <package>

 

Command:

x64

sudo rpm -e java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686

 

x32

To uninstall java-1.6.0-openjdk-1.6.0.0-3.1.13.1.el6_5.i686

sudo rpm -e java-1.6.0-openjdk-1.6.0.0-3.1.13.1.el6_5.i686

 

To uninstall java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.i686


sudo rpm -e rpm -e java-1.7.0-openjdk-1.7.0.51-2.4.4.1.el6_5.i686

but, we get

Textual:


error: Failed dependencies:
libjawt.so(SUNWprivate_1.1) is needed by (installed) libreoffice-core-1:4.0.4.2-9.el6.i686

Image:

openJDKNeededByLibreOffice

 

with the strong confirmation that LibreOffice is using open JDK 1.7, we are going to have to live with it.

Installed Files – Java

List installed locations and files for Sun\Oracle Java

Table:

Folder Binary
/usr/java/jdk1.8.0/jre/bin
java
javaws
 /usr/java/jdk1.8.0/bin
jar
java
javac
javaws

 

 

 

Alternatives – Install / Updates – Console

Alternatives can be used to manage cases where an Application is bundled by one more Vendor.  Or where a couple of versions is installed by same Vendor.

Let us register our installed Sun/Oracle java as an alternative.

Syntax:


alternatives --install <link> <name> <path> <priority>

 

Command:


## java ##
alternatives --install /usr/bin/java java /usr/java/jdk1.8.0/jre/bin/java 20000

## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0/jre/bin/javaws 20000 

## Install javac only if you installed JDK (and we did)
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0/bin/javac 20000 

##install jar only if you installed JDK (and we did)
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0/bin/jar 20000 


Alternatives – Update

Command:

## java ##
sudo update-alternatives --set java /usr/java/jdk1.8.0/jre/bin/java
sudo update-alternatives --set javaws /usr/java/jdk1.8.0/jre/bin/javaws

## Install javac/jar only if you installed JDK package 
sudo update-alternatives --set javac /usr/java/jdk1.8.0/bin/javac
sudo update-alternatives --set jar /usr/java/jdk1.8.0/bin/jar

 

If you get an error message that reads:

“/usr/bin/jdk1.8.0/jre/bin/java has not been configured as an alternative for java”, then please review the earlier batch of “alternatives –install” and make sure that you have typed the correct and full path name to your binary files

HasNotBeenConfiguredAsAnAlternativeForJava

 

Update System Path File (/etc/profile)

Using your editor of choice, Add the following to the bottom of your /etc/profile:

In our case, we will use vi and invoke as “sudo vi /etc/profile

# Update System with Sun\Oracle Java Information
# set JAVE_HOME to Sun\Oracle Install Location
JAVA_HOME=/usr/java/jdk1.8.0

# set JRE_HOME to Sun\Oracle Install location
JRE_HOME=/usr/java/jdk1.8.0

# add User $HOME/bin and aforementioned $JAVA_HOME/bin to path
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

 

 

Effect System Path File (/etc/profile) Changes

Since we do not want to force a restart before we proceed, let us force execution of our /etc/profile.

sudo sh /etc/profile

 

Review Alternatives – Java

Update-alternatives –display

Syntax:

update-alternatives --display <app-name>

 

Command:

update-alternatives --display java | egrep "link | priority"

 

Output:

UpdateAlternatives -- display java

Explanation:

  • We see that our current alternatives pointer is directed @ /usr/java/jdk1.8.0/jre/bin/java

 

Update-alternatives –config

 

Syntax:

update-alternatives --config java

 

Output:

alternatives --config

 

Explanation:

  • Selection 2 is tagged with an *, as “Open JDK 1.7” has the highest priority ( 170051 )
  • Selection 3 is tagged with a +, as the Sun/Oracle’s  JRE Java is our current selection

Review Install Java Version

Java Version?

Command:

java -version

 

Output:

java_version_question

 

Javac Version?

Command:

javac -version

 

Output:

javac_version_question

References

References – Java on CentOS

 

References – Java on Debian

 

References – Java on Ubuntu

 

References – Alternatives – Java

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s