Friday, June 22, 2012

Oracle (sun) java 6 install

I am currently running Mint Linux 13 which comes with OpenJDK/JRE but I require Oracle(Sun) Java here is how to install manually.  I know there are PPA's out there but I do not find them very reliable since Oracle seem to have some licensing issue with 3de parties hosting Java binaries.

Step 1: Download

Go to the Oracle site and select your Java. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 2: Extract

I downloaded Java 7 JDK so to extract was simply

 tar -xvf ~/Downloads/jdk-7u5-linux-x64.tar.gz  

Step 3: Move

When you install Java via a package manager for a Debian system the install location is /usr/lib/jvm/.  If you go have a look at that folder you should see all the installed version of java on you pc.  So to move the extracted folder:

 sudo mv ~/Downloads/jdk1.7.0_05 /usr/lib/jvm/java-7-sunjdk  

This will move and rename the folder to java-7-sunjdk

Step 4: Install

Linux has this amazing command to where you can link commands with the option of easy switching.

So to list all the currently installed options for the command java type

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  

As you can see here I only have Java 6 OpenJDK installed for the command java.  Now to add my Oracle java I will have to install a new option as follow:

 sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-7-sunjdk/bin/java" 1  

Now if I rerun the list command I have two options for the java command

 user@user-SERVER ~ $ sudo update-alternatives --list java  
 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  
 /usr/lib/jvm/java-7-sunjdk/bin/java

Step 5: Select Default

Now to select which one must be executed by default if I run the java command:

 user@user-SERVER /usr/lib/jvm $ sudo update-alternatives --config java  
 There are 2 choices for the alternative java (providing /usr/bin/java).  
  Selection  Path                      Priority  Status  
 ------------------------------------------------------------  
 * 0      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   auto mode  
  1      /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  1061   manual mode  
  2      /usr/lib/jvm/java-7-sunjdk/bin/java       1     manual mode  
 Press enter to keep the current choice[*], or type selection number: 2  
 update-alternatives: using /usr/lib/jvm/java-7-sunjdk/bin/java to provide /usr/bin/java (java) in manual mode.  

When you run this command you are show the current default and all the available options.  In my case I selected option 2 as my new default.

Step 6: Jippy

Your all done below are just some command for the ease to map the javaws, javac and jps.  Your more than welcome to add more.

 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-7-sunjdk/bin/javac" 1  
 sudo update-alternatives --config javac  
 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java-7-sunjdk/bin/javaws" 1  
 sudo update-alternatives --config javaws  
 sudo update-alternatives --install "/usr/bin/jps" "jps" "/usr/lib/jvm/java-7-sunjdk/bin/jps" 1  
 sudo update-alternatives --config jps  

No comments:

Post a Comment