Wednesday, July 29, 2009

Installing Sun Java on Ubuntu

Java run time and java plug n is an essential component you need on any decent linux desktop.
They are required for running applications as well as browsing java enabled web pages. Several flavours of java is available on the repository. Some of them may not have full functionality. Here's how to install Java run time and java plug in on ubuntu. Even though Java was a popular environment on many platforms, the linux distributions were not bundling it due to the restrictive licecnse . Recently, however, Sun Microsystems relaxed the restrictions on the Java license, introducing the Distro License for Java (DLJ). This new license allows distributors to ship Sun's JRE and Java Development Kit (JDK) as installable packages, rather than the self-extracting binaries that were previously available. It also gives Linux distributors the ability to define the packaging, installation, and support for Java within their Linux distribution.

As such, ubuntu 9.04 Jaunty now ships with Sun's Java available as a non-free package in the multiverse repository. You'll need to have the universe and multiverse repositories enabled to install Java.
On ubuntu the java is available as several components which you can use as per your requirement. Both java 5 and java 6 packages are available.

Try apt-cache search sun-java and see the full list of java related packages Some of the important packages you may see are,

sun-java5-bin Contains the binaries
sun-java5-demo Contains demos and examples
sun-java5-doc Contains the documentation
sun-java5-fonts Contains the Lucida TrueType fonts from the JRE
Contains the metapackage for the JDK
sun-java5-jre Contains the metapackage for the JRE
sun-java5-plugin Contains the plug-in for Mozilla-based browsers
sun-java5-source Contains source files for the JDK

A similar set of pakages exists for java 6

Installing the Java Runtime Environment

Once you've got the multiverse repository enabled, installing Sun's Java package is easy. Simply open a terminal window and apt-get the package.

~$ sudo apt-get install sun-java5-jre sun-java5-plugin sun-java5-fonts

Once apt-get downloads the packages and begins the installation, you'll get a screen that contains the Sun Operating System Distributor License for Java. Read the license, if you wish, and hit Enter to continue. You'll see a dialog that asks you if you agree with the DLJ license terms. Select Yes, and hit Enter; the JRE will finish installing.
At this point, Java is installed.

You'll want to confirm that your system is configured properly for Sun's JRE. This is a two-step process. First, check that the JRE is properly installed by running the following command from a terminal. You should get similar output:

$ java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Server VM (build 11.3-b02, mixed mode)

If you see an unexpected version of Java in particular some thing like the lines below, you may have Open JDK installed.

java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu7)
OpenJDK Server VM (build 14.0-b08, mixed mode)

You can easily switch from one Java to another with the following command

$ sudo update-alternatives --config java

See the screen shot below

If the JRE is properly installed, confirm that the Java plug-in is installed in your browser by opening Firefox and typing about:plugins in the address bar . Look for java and verify that it is enabled.

Installing Java compiler.

If you are planning to develop applications using java , you can install
jdk as below.

$ sudo apt-get install sun-java5-jdk

1 comment:

chrisonline1991 said...

In ubuntu 9.10 Java is verison 6 in the repos so just change the 5 to 6 for all the packages.