Thursday, May 2, 2013

Install oracle JDK in Ubuntu


Oracle retired the Operating System Distributor's License for Java, meaning that Canonical could no longer include the JDK or JRE in their APT repositories. This means no more "sudo apt-get install sun-java-whatever"

New Ubuntu installation comes with an open source implementation of Java SE installed, called OpenJDK (Open Java Development Kit), which is not compatible with applications written in Oracle Java.

Following are the steps to install Oracle JDK into Ubuntu

1. Download JDK package in http://www.oracle.com/technetwork/java/javase/downloads/index.html


for Linux x86 (32-bit) : jdk-7u21-linux-i586.tar.gz
for Linux (64-bit) : jdk-7u21-linux-x64.tar.gz

2. Extract the package

tar -xf jdk-7u21-linux-i586.tar.gz

This will extract and create a jdk folder at your current path.

3. Create a location to keep your new JDK . I prefer and usually use /usr/lib/jvm/
You may need root permission to create the /usr/lib/jvm (hence use sudo).

sudo mkdir /usr/lib/jvm

4. Move the extracted jdk folder to /usr/lib/jvm/

sudo mv jdk1.7.0_21 /usr/lib/jvm/

5. Now we have to setup our system to use refer to our new jdk

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_21/bin/java" 1 

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_21/bin/javac" 1 


sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_21/bin/javaws" 1


6. JAVA_HOME environment variable

vi /etc/bash.bashrc

 then add following line in endof the file

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH


7 . All done.
When you reboot, try running the following:

$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.7.0_21
 echo $PATH
usr/lib/jvm/jdk1.7.0_21 /bin



No comments:

Post a Comment