Installing Java JRE and JDK version 1.7(1.6) on CentOS 6 and config the system alternatives for "java"

You should simply use the packages from Sun.

Step (1) : Visit Sun’s web site and download the latest version of Java (the *.bin file not the *-rpm.bin) (http://java.sun.com/javase/downloads/index.jsp)

(pay close attention if you want the 32bit or 64bit version)

Example the 64-bit version of the JDK can be found at http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.rpm

The 64-bit version of the Java Runtime Enviroment ca be found at http://download.oracle.com/otn-pub/java/jre/7/jre-7-linux-x64.rpm

Step (2) :

[user@localhost]# cd <your download location>

[user@localhost]# wget http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.rpm

[user@localhost]# wget http://download.oracle.com/otn-pub/java/jre/7/jre-7-linux-x64.rpm

[user@localhost]# /bin/sh jdk-7-linux-x64.bin

 

Step (3) : Setup the alternatives correctly

JDK 1.7.0 instructions:
[user@localhost]# alternatives --install /usr/bin/java java /usr/java/jdk1.7.0/bin/java 1
[user@localhost]# alternatives --install /usr/bin/java java /usr/java/jre1.7.0/bin/java 2
 
JDK 1.6.0_34 instructions:
[user@localhost]# alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_34/bin/java 1
[user@localhost]# alternatives --install /usr/bin/java java /usr/java/jre1.6.0_34/bin/java 2

There are 2 programs which provide 'java'.

[user@localhost]# alternatives --config java

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jre1.7.0/bin/java
   2           /usr/java/jdk1.7.0/bin/java
 
Enter to keep the current selection[+], or type selection number: 2 
[user@localhost]#

Step (4) : Check to make sure the install was a success

[user@localhost]# java -version 
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0)
Java HotSpot(TM) 64-Bit Server VM (build 21.0, mixed mode)

If you are going to do Java Development or Install a Java Framework/Java Source you should make sure your java virtual machine is set to call the JDK

Step(5) : Check your version of java you have as default.  This uses the alternatives options to display the java default JVM.

[user@localhost]# alternatives --display java

/usr/java/jdk1.7.0/bin/java - priority 2
/usr/java/jre1.7.0/bin/java - priority 1
Current `best' version is /usr/java/jdk1.7.0/bin/java. <---- Make sure this line display the JDK if you are doing Java Development or Install Java Frameworks

Step(6) : If you require the JDK issue the command :

javac -versiion  

javac 1.7.0 <----- You should see this if your JDK was installed correctly.


-