Pages

Installing JDK on Linux

Tuesday, 5 February 2013

Installing SUN-JDK on Linux




While many of our applications are based on java framework. We definitely need the
Java development kit for running the java based applications.

So Lets start with What actually is a JDK

A Java Development Kit (JDK) is a program development environment for writing Java applets and
applications. It consists of a runtime environment that "sits on top" of the operating system
layer as well as the tools and programming that developers need to compile, debug, and run
applets and applications written in the Java language.


A JDK comprises of lots of useful components( programming tools ) namely
java
javac
javadoc
appletviewer

Now that you know what a JDK, I am sure many of the beginners( I was one of them ) would be
confused between the term JDK and JRE.

So what is the difference between JDK and JRE


The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to
develop Java based software.
The "JRE" is the Java Runtime Environment. I.e., the JRE is an implementation of the Java Virtual
Machine which actually executes Java programs. ( John Mitchell )

JRE is a subset of JDK. A java program always execute in two steps, compile and interpret
JDK does the compilation but JRE can't, where as interpretation can be done by both
JDK and JRE

Typically, each JDK contains one (or more) JRE's along with the various development tools like the
 Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

Now that you might have an idea on JDK and JRE concepts, Lets not waste time and move ahead to our
next section of Installing JDK

We will be installing JDK on two different OS ( Centos & Ubuntu )

First we need to decide on the JDK which we will be using, there are many distribution of JDK available
open source on the internet namely Sun-JDK, Open-JDK, IBM J9, Redhat's IcedTea

We will be considering SUN-JDK, the most trusted JDK available

Note: The same tutorial can be used to install JDK before starting to install Hadoop.
          JDK is a primary pre requisite for installing Hadoop .

Installing on Centos 6.3




1. First we need to download jdk from the http://www.oracle.com/technetwork/java/javase/downloads/index.html
   Select a appropritae rpm to download depending on your OS whether 64 or 32 bit. The files will be like
   jdk-7u13-linux-i586.rpm
2. Once you get the above rpm file place it on your Centos server
3. Login with root access
4. Check if you already have JAVA distribution by using
   java -version
   If found it might be OpenJDK, or else there will be no JAVA distribution on your system
5. Installing the rpm
   [root@centos] rpm -iv jdk-7u13-linux-i586.rpm
                 Unpacking JAR files…
                 rt.jar…
                 jsse.jar…
                 charsets.jar…
                 tools.jar…
                 localedata.jar…
6. By default JAVA will be installed in /usr/java.jdk1.7.0/
7. Now you need to add the new java to aternatives configuration and update the JAVA alternatives
  [root@centos] alternatives --install /usr/bin/java java /user/java/jdk1.7.0/bin/java 2
  [root@centos] alternatives --config java
 
 
   Selection Command
   ———————————————–
   1. /usr/java/jdk1.7.0/bin/java
   Enter to keep the current selection[+], or type selection number: 1


  The above command will show you the list of programs providing JAVA, you need to select one default for
   your system


8. Now verify the java version on your system

   [root@centos] java -version
   [root@centos] java version “1.7.0″
              Java(TM) SE Runtime Environment (build 1.7.0-b147)
              Java HotSpot(TM) 32-Bit Server VM (build 21.0-b17, mixe mode)


Installing on Ubuntu Lucid 10.4





1. We will be using the apt-get command and not by donwloading the binary package as we did above to get the Sun-JDK working
2. Login to your ubuntu system as root
3. Update your source list

 [root@ubuntu] apt-get update

4. Install Sun Java 6 JDK
 
 [root@ubuntu] apt-get install sun-java6-jdk

5. The sun java should be installed in folder /usr/lib/jvm/java-6-sun
6. Now we need to update the alternatives in order to let ubuntu use the Sun's JDK as defualt

   [root@ubuntu] update-java-alternatives -s java-6-sun
   [root@ubuntu] update-alternatives --config java

7. Checking the JAVA version on your system

  [root@ubuntu] java -version
               java version "1.6.0_20"
               Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
               Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

  Now you are good to go with JDK installed on your systems.

No comments:

Post a Comment

Follow by Email