Ubuntu: Changing the default java binary

Since upgrading to Karmic I've had a weird issue with Charles Proxy in that the windows for settings like rewrites seemed to get completely screwed up making it very difficult to see the boxes for entering information. Here's a screenshot of what it looks like broken.

Karl von Randow the author of Charles was looking into the issue following my bug report and after he'd been unable to reproduce the issue in a fresh install of Ubuntu Karmic with a Java Runtime downloaded from the sun site he suggested I do the same, as I was currently showing that I was running the OpenJDK java runtime.

This prompted me to do a little more digging as I prefer to only use packaged software where possible mainly for the big benefit of getting security and other updates as soon as they are made available.

On my system I had both the sun-java6-jre package as well as the openjdk-6-jre package installed.

To check which one you are using run the following command from the terminal:

$ java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-3ubuntu1)
OpenJDK Server VM (build 14.0-b16, mixed mode)

To fix the problem I used the following command to switch to the SUN java binary.

sudo update-alternatives --config java
# Enter password #
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

Selecting 2 and hit enter and now the version is as expected.

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

Running Charles again the windows that were broken now display correctly.

Show Comments