Wednesday, January 21, 2009

Install Java6 on Kubuntu Linux

After having a stable KDE 4.1.9, I decided to test the Java compiler installation from Sun.

How to select the default Java
More than one Java can be installed at a time on Linux. The default Java can be set by user. If you have Java installed, then choose the correct version:

  • Check the current Java or JRE
    java -version
  • Check the installed Java JDK
    update-java-alternatives --list
  • Select default Sun's Java or JRE
    sudo update-java-alternatives -s java-6-sun
  • Example output of installed Java
    java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
    java-6-sun 63 /usr/lib/jvm/java-6-sun

Installing java
Step 1. Be connected to the Internet. Check the Java version and details prior to installation then install Sun Java Development Kit.

apt-cache show sun-java6-jdk
sudo apt-get install sun-java6-jdk sun-java6-doc sun-java6-demo

Step 2. The JDK documentation installation requires the file from Sun Website. Download the Java Doc files from http://java.sun.com/javase/downloads/
Select Java SE 6 Documentation and download to /tmp.

Step 3. Select default Sun's Java or JRE
sudo update-java-alternatives -s java-6-sun

Step 4. Apply the Java compiler path in ~/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

Step 5. Install Eclipse 3.2 IDE
sudo apt-get install eclipse eclipse-jdt

Compiling Java
Create the first Java program, compile then execute.

Step 1: Below is the traditional Hello World example for the Java program called Hello.java

class Hello {
public static void main( String args[]){
System.out.println( "Hello World");
}
}

Step 2. Compile.

javac Hello.java

Step 3. Execute.

Java Hello

No comments: