How-To: Install the Official Sun JDK in Ubuntu

Update: I wrote this to switch out the JRE in Ubuntu 10.04, and it’s still valid & works in Ubuntu 10.10 =D

The default java solution for Ubuntu 10.04 is the OpenJDK virtual machine and the IcedTea plugin for firefox – but I’ve been having serious issues with it locking up, taking up 100% CPU and other such craziness – so I’ve switched over to the (proprietary) official Sun JDK, and things are working much better. Here’s how I did it, and how you can too…

1.) Add the Lucid Partner repository to your Sources list

We’re going to be installing the Sun JDK through the repos, and it just so happens that we need the partner repo enabled, so you can either add the following line to your /etc/apt/sources.list, or you can check the box in System | Administration | Software Sources (assuming you’re using Gnome – pick whatever source managing front-end KDE uses if that’s your poison):

Shell

1

deb http://archive.canonical.com/lucid partner

or..

2.) Install the Sun JDK and Plugin

Before you install the good stuff, it’s an idea to check your current version so you can see the changeover’s worked. To do this, just run java -version from bash and you should see something like this:

Shell

1

2

3

java version"1.6.0_18"

OpenJDK Runtime Environment(IcedTea61.8)(6b18-1.8-0ubuntu1)

OpenJDK64-Bit Server VM(build14.0-b16,mixed mode)

Once you know what you’ve currently got, again from the shell, enter the following to install the official Sun JDK (don’t worry about multiple JDKs being installed – we deal with that later):

Shell

1

sudo apt-getinstall sun-java6-jre sun-java6-plugin sun-java6-fonts

During this process you’ll have to agree to the license agreement – just hit Tab to switch focus in the text window onto the Yes button (assuming you do agree), and hit Enter to accept.

The JRE EULA - Slap the Tab key followed by Enter to ensure swift installation and that Oracle (they bought Sun, remember?) now own your first born child...

3.) Remove the old OpenJDK stuff

In Synaptic, you want to fully remove the following packages (if they’re installed – the top three in the below list might not be):

Shell

1

2

3

4

5

6

7

8

9

default-jdk

default-jre

default-jre-headless

icedtea-6-jre-cacao

icedtea6-plugin

openjdk-6-jdk

openjdk-6-jre

openjdk-6-jre-headless

openjdk-6-jre-lib

If you do this before installing the Sun JDK, all packages depending on Java will be removed as well – so in this rare instance, later is better, and any packages depending on Java can now stay on the system.

4.) Check it all works

From the command line enter: java -version and you should see the new details:

Shell

1

2

3

java version"1.6.0_20"

Java(TM)SE Runtime Environment(build1.6.0_20-b02)

Java HotSpot(TM)64-Bit Server VM(build16.3-b01,mixed mode)

If you want the new plug-in to take effect in Firefox or such you need to restart the browser, then you should be all good to go! Maybe test it out at sodaplay for kicks too :)