Tuesday, August 26, 2014

Install Oracle Sun Java to CentOS


Install Oracle Sun Java to CentOS

Download Oracle Java 7 JDK for Linux:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
I prefer RPM. The tar.gz is an alternative available mainly for non-root users.

Note for x86 and x64
You can choose between x86 and x64 versions. You cannot install both together from RPM package. You can install one from RPM and the second manually from tar.gz.

Download (accept licence):
http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm

Download (shell command)
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm

Install java from rpm:
rpm -i *.rpm

Upgrade Java (optional):
rpm -Uvh jdk-7u-linux-x64.rpm

Setup Java
## java
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 200000

## javaws
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 200000

## Install javac only if you installed JDK (Java Development Kit) package
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 200000

Choose Oracle Java as default
alternatives --config java
alternatives --config javaws
alternatives --config javac

Setup path
Add to /etc/profile file or ~/.bash_profile or to ~/.bashrc
export JAVA_HOME="/usr/java/latest"
Java JDK and JRE absolute version (/usr/java/jdk1.7.0_67)

Check version
java -version
javac -version

Resources

Oracle Java install doc:
http://docs.oracle.com/javase/7/docs/webnotes/install/
http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html

All steps in detail at:
http://www.if-not-true-then-false.com/2010/install-sun-oracle-java-jdk-jre-7-on-fedora-centos-red-hat-rhel/

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

Done


No comments: