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.
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.
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
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
# /usr/java/jdk1.6.0/bin/java -versionYou 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 PATHA 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
$ vi HelloWorld.javaAnd enter this code:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}
2) Compile:
$ javac HelloWorld.java3) Run:
$ java HelloWorld<15-Jan-2007>