Next Previous Contents

2. How to Setup the Java Development Kit

This document will only discuss the J2SE JDK from Sun.

NOTE: In this document I will refer to $HOME, which in my case is /home/doug. You may use whatever directory is convenient for you.

2.1 Sun J2SE: Installation

The first thing you'll need to do is download the latest Java SE Development Kit (JDK) for Linux from http://java.sun.com/j2se/downloads.html/. The latest version as of this writing is Java SE JDK 6 (1.6.0). You can either use a self-extracting file or a RPM (from a self-extracting file). Download the SDK, not the JRE.

The "RPM in self-extracting file" will install Java in /usr/java by default. The "self-extracting file" will install Java in whatever directory you run the file from.

Linux RPM in self-extracting file

Download and copy jdk-6-linux-i586-rpm.bin to $HOME/src (or a temporary location of your choice).

% su -
# cd $HOME/src
# chmod +x jdk-6-linux-i586-rpm.bin
# ./jdk-6-linux-i586-rpm.bin (this will create and run jdk-6-linux-i586.rpm)
# rm jdk-6-linux-i586-rpm.bin
# rm jdk-6-linux-i586.rpm

Linux self-extracting file

Download and copy jdk-6-linux-i586.bin to $HOME/src (or a location of your choice).

% su -
# mkdir /usr/java (if it doesn't exist)
# mv $HOME/src/jdk-6-linux-i586.bin /usr/java
# cd /usr/java
# chmod +x jdk-6-linux-i586.bin
# ./jdk-6-linux-i586.bin

2.2 Sun J2SE: Configuration

Now test Java:
# /usr/java/jdk1.6.0/bin/java -version
You should something like this:
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

Set the PATH and JAVA_HOME environment variables: (/etc/profile, $HOME/.bashrc or $HOME/.bash_profile).

PATH=$PATH:/usr/java/jdk1.6.0/bin
JAVA_HOME=/usr/java/jdk1.6.0
export PATH
A reference to the current directory will probably need to be added to your CLASSPATH. Add ":." to the end of your CLASSPATH. Relog into your shell. Now you should be able to access java like this:
# java -version

2.3 Sun J2SE: Test

1) Write a simple java program, HelloWorld.java.

$ vi HelloWorld.java
And enter this code:
public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello world");
  }
}
2) Compile:
$ javac HelloWorld.java
3) Run:
$ java HelloWorld

<15-Jan-2007>
Next Previous Contents