Sunday, February 2, 2014

Java - Setup - Install Oracle JDK in Ubuntu

JDK Version: Java 7 (and 1.6.0_45 64bit)
Operation System: Ubuntu 14.04 (and Ubuntu 12.04 64 bit)



Check if java is installed:
Command: java -version

If below message is displayed on screen, meaning java not installed

The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless

Try: apt-get install



How to remove openJDK
This step might be needed if openJDK is not preferred and want to install Oracle JDK.

Command: "sudo apt-get purge openjdk-\*"

Install JDK - steps to follow :
  • Install packages directly. Below commands are for Java 7. Might need to change with 'Java7' to appropriate version (like Java8).
    Commands:
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
    sudo apt-get install oracle-java7-set-default
  • Using .bin extension installer (this I tried with Java 6 on Ubuntu 12 earlier)
    1. Download JDK version from Oracle. File name is 'jdk-6u45-linux-x64.bin'
    2. Copy downloaded folder to '/usr/local/java'. (need to create the folder if desn't exist)Command: "sudo mkdir -p /usr/local/java" (to create folder)"sudo cp jdk-6u45-linux-x64.bin /usr/local/java/"
    3. Set the executable permissionsCommand: "sudo chmod a+x jdk-6u45-linux-x64.bin"
    4. Add java to the path.
      C
      ommand:"sudo gedit /etc/profile" (gedit editor is used)
      Lines need to be added in the profile. 
      JAVA_HOME=/usr/local/java/jdk1.6.0_45PATH=$PATH:$HOME/bin:$JAVA_HOME/binJRE_HOME=/usr/local/java/jdk1.6.0_45/jrePATH=$PATH:$HOME/bin:$JRE_HOME/binexport JAVA_HOMEexport JRE_HOMEexport PATH
    5. Inform Ubuntu where to look for JDKCommand:"sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.6.0_45/jre/bin/java" 1"
      "sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.6.0_45/bin/javac" 1
      "
      "sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.6.0_45/bin/javaws" 1
      "
    6. Inform Ubuntu Linux system that Oracle Java JDK must be the default JavaCommand: "sudo update-alternatives --set java /usr/local/java/jdk1.6.0_45/jre/bin/java"
      "
      sudo update-alternatives --set javac /usr/local/java/jdk1.6.0_45/bin/javac"
      "
      sudo update-alternatives --set javaws /usr/local/java/jdk1.6.0_45/bin/javaws"
    7. Load profile changesCommand:  "./etc/profile"

Test java successfully installed:

Command: "java -version"

Output: 
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

No comments: