Saturday, January 19, 2013

How to Install Java (OpenJDK) on Ubuntu


Before proceeding the installation, check first the existing Java installed in your system.

$ sudo java -version

 Once confirmed that there is an existing different version of Java installed, then execute the command below.

$ sudo update-java-alternatives -l
The command will show you the list all installed java packages.

Proceed with the installation of OpenJDK if they are yet in the list of the installed java packages.
 
$ sudo apt-get install openjdk-6-jdk

Verify if OpenJDK was successfully installed.

$ sudo apt-cache search openjdk

Since the system has more than one version of Java installed, then configure Java and set OpenJDK as the system use by executing the following command.

$ sudo update-alternatives --config java
You will be prompted with the choices e.g.
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number: 0

Check again the version and that's it!