Install Java JRE 1.6.0 (Update x) in Linux as the Default Java Runtime, including Firefox Browser Plugin

Posted by on Aug 2, 2008 in Featured, Linux, Ubuntu110 comments

Java JRE Logo

I wanted the latest version of Sun’s JRE installed on my system, and to have it set up as the default Java Runtime Environment whenever I ran a Java executable, or Jar file. It’s actually a pretty easy process, so this is a relatively short tutorial, but I’ll cover both the 32 bit and 64 bit installations, since aside from differences in file names, the set up is identical.

Changelog

Update 12/10/09: JRE 1.6.0 u16 now available!

Update 19/08/09: JRE 1.6.0 u15 now available!

Update 29/06/09: JRE 1.6.0 u14 now available!

Update 29/03/09: JRE 1.6.0 u13 now available!

Update 05/02/09: Updated for u12, which now includes the 64 bit Browser Plugin!

Installing JRE

First, decide on which architecture will be installed, and download the relevant file from the main Java website – if you’re running a 64 Bit Linux OS, download the 64 Bit JRE.

At the time of writing, 1.6.0 u16 can be downloaded from the following: 32 bit JRE, and 64 bit JRE. I wanted to install the x64 version, and so downloaded jre-6u16-linux-x64.bin to my Desktop. I also wanted to install it in its own directory in /opt, and so created a directory for it to sit in:

cd /opt
sudo mkdir java

I was also experimenting with the 32 and 64 bit versions, so made two extra directories within java:

cd java
sudo mkdir 32 64

I then moved the relevant file(s) to the respective directories, and made them executable:

32 bit:

sudo mv ~/Desktop/jre-6u16-linux-i586.bin /opt/java/32
sudo chmod 755 /opt/java/32/jre-6u16-linux-i586.bin

64 bit:

sudo mv ~/Desktop/jre-6u16-linux-x64.bin /opt/java/64
sudo chmod 755 /opt/java/64/jre-6u16-linux-x64.bin

The final part of the installation simply involves executing the binary file:

32 bit:

cd /opt/java/32
sudo ./jre-6u16-linux-i586.bin

64 bit:

cd /opt/java/64
sudo ./jre-6u16-linux-x64.bin

Regardless of architecture, this should create a sub directory called jre1.6.0_16.

Setting JRE 1.6.0 u16 as Default

The process simply involves telling the system that there is an alternative Java binary available, and to use this binary to execute an “java” commands:

32 bit:

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/32/jre1.6.0_16/bin/java" 1
sudo update-alternatives --set java /opt/java/32/jre1.6.0_16/bin/java

64 bit:

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/64/jre1.6.0_16/bin/java" 1
sudo update-alternatives --set java /opt/java/64/jre1.6.0_16/bin/java

Follwing the second command, there should be output to the terminal something along the lines of:

Using '/opt/java/32/jre1.6.0_16/bin/java' to provide 'java'.

or,

Using '/opt/java/64/jre1.6.0_16/bin/java' to provide 'java'.

depending on the architecture installed.

To double check everything is as it should be, in a Terminal run:

java -version

This should output something along the lines of:

java version "1.6.0_xx"
Java(TM) SE Runtime Environment (build 1.6.0_xx)
Java HotSpot(TM) 64-Bit Server VM (build xxxx, mixed mode)

That’s it. Now every time “java” is run, either explicitly from the Terminal, or via a Java executable (such as the Eclipse IDE), the newly installed /opt/java/64/jre1.6.0_16/bin/java binary will be used as opposed to the binary installed by default. Simple, eh?

Installing the Browser Plugin

Note: For the 64 bit plugin, it is strongly recommended that you use the version of Firefox available for installation via your distribution’s repositories.

As with most Firefox plugins, they can be installed in ~/.mozilla/plugins – if it doesn’t exist, it can be created:

mkdir ~/.mozilla/plugins

It may also be necessary to uninstall any previous Java installations, such as IcedTea etc.:

sudo apt-get remove icedtea-gcjwebplugin

Note: if you’re upgrading from a previous JRE install, remove the old plugin first:

32 Bit:

rm ~/.mozilla/plugins/libjavaplugin_oji.so

64 Bit:

rm ~/.mozilla/plugins/libnpjp2.so

The Plugin can now be installed by either copying the file:

32 Bit:

cp /opt/java/32/jre1.6.0_16/plugin/i386/ns7/libjavaplugin_oji.so ~/.mozilla/plugins/

64 Bit:

cp /opt/java/64/jre1.6.0_16/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

or by creating a symbolic link to the file (this is the best option)

32 Bit:

ln -s /opt/java/32/jre1.6.0_16/plugin/i386/ns7/libjavaplugin_oji.so ~/.mozilla/plugins/

64 Bit:

ln -s /opt/java/64/jre1.6.0_16/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

Once installed, restart Firefox. There are two methods to see if the Plugin is installed – navigate to about:plugins

jre-64bit-browser-plugin

or to the Java Tester Page

jre-64bit-browser-java-tester

That’s it. Enjoy :)

Tags: , ,