How to setup the Oracle Java Plug-in on Ubuntu Linux

Ubuntu is a Certified System Configuration for Java SE 7. This article describes how you can setup the Oracle Java Plug-in on Ubuntu Linux. The directories and paths used in this article represent fictitious sample names that make up an example. Any similarity to actual code is purely coincidental and not intended in any other manner.

1. Download and install the JRE or the JDK

Tip: Since the JDK comes comes with useful tools that could help you to troubleshoot Java applets in case of problems, we recommend that you install the JDK instead of the JRE.

Ubuntu is based on Debian. For now Oracle does not offer a .deb, but you can install the JDK (or JRE) by using an archive binary file according to the instructions at

http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html#install-64

and at

http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html#install-32

For the following steps, it is assumed that you have installed the 64-bit JDK at /opt/oracle/java/jdk/64/latest7

Tip: latest7 could be a symbolic link that points to an actual JDK folder. That way you can easily update the JDK just by modifying the symlink, step 2 would need to be done only once then.

Example:

I have downloaded the 64-bit JDK file called jdk-7u45-linux-x64.tar.gz using the Ubuntu Firefox browser and I have stored the file to the ~/Downloads folder. I created the folder /opt/oracle/java/jdk/64 where the JDK should be stored. I extracted the tarball to that folder and created a symlink so that the latest JDK can always be found at /opt/oracle/java/jdk/64/latest7

$ sudo mkdir -p /opt/oracle/java/jdk/64
$ cd /opt/oracle/java/jdk/64
$ sudo tar zxvf  <path_to>/jdk-7u45-linux-x64.tar.gz
$ sudo ln -s jdk1.7.0_45 latest7</path_to>

2. Setup the Oracle Java Plug-in

On Ubuntu, the Mozilla Firefox browser is built by Canonical and it is part of the system. In order to configure the Oracle Java Plug-in on Ubuntu properly, you can use the command called update-alternatives.

Notes: manually fixing symlinks such as usr/lib/mozilla/plugins/libjavaplugin.so or /etc/alternatives/mozilla-javaplugin.so can cause the update-alternatives command to display incorrect values or even fail to start. Therefore it is recommended to use the update-alternatives command in order to install and configure the desired symlinks instead of modifying the symlinks manually.

The folder where I have stored the JDK is printed in bold in the example below. Please modify that path according to your installation.

For the 32-bit JDK (and a 32-bit browser):

$ sudo update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so "/opt/oracle/java/jdk/32/latest7/jre/lib/i586/libnpjp2.so" 1
$ sudo update-alternatives --config mozilla-javaplugin.so

For the 64-bit JDK (and a 64-bit browser):

$ sudo update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so "/opt/oracle/java/jdk/64/latest7/jre/lib/amd64/libnpjp2.so" 1
$ sudo update-alternatives --config mozilla-javaplugin.so

Example:

$ sudo update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so "/opt/oracle/java/jdk/64/latest7/jre/lib/amd64/libnpjp2.so" 1
$ sudo update-alternatives --config mozilla-javaplugin.so
There are 4 choices for the alternative mozilla-javaplugin.so (providing /usr/lib/mozilla/plugins/libjavaplugin.so).

  Selection    Path                                                              Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so   1061      auto mode
  1            /java/jdk/64/latest6/jre/lib/amd64/libnpjp2.so                     1         manual mode
* 2            /java/jdk/64/latest7/jre/lib/amd64/libnpjp2.so                     1         manual mode
  3            /opt/oracle/java/jdk/64/latest7/jre/lib/amd64/libnpjp2.so          1         manual mode
  4            /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so   1061      manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /opt/oracle/java/jdk/64/latest7/jre/lib/amd64/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in manual mode.
$

3. Restart the browser and verify the new version

After the setup is done, please restart your browser and go to https://www.java.com/verify in order to verify the new version.

4. Update the JDK or the JRE

If a new Java update release is available and if you have created a symlink for the JDK folder as described in step 1, you can update the JDK very easily without the need to do step 2 again.

Example:

I am going to update the 64-bit JDK to Java SE 7 update 51 just by bending the symlink.

$ cd /opt/oracle/java/jdk/64
$ sudo tar zxvf  <path_to>/jdk-7u51-linux-x64.tar.gz
$ sudo rm latest7
$ sudo ln -s jdk1.7.0_51 latest7</path_to>

After that, restart the browser again in order to get the new Java Plug-in from 7u51.