August, 2011

Sun invented Java, as every English schoolboy knows. Sun was purchased by Oracle, and Java was part of the deal, so now you get Sun Java from Oracle - or maybe you get Oracle Java from Oracle. Whatever it is you get, you get it from Oracle these days. You can instead, just use OpenJDK on a linux system, and that is often an easier and perfectly adequate thing to do. I went through the following process when I was grasping at straws trying to get a balky Java application (called "arduino") to run on my system -- it turns out OpenJDK would have been fine.

The websites java.sun.com and java.oracle.com both seem to work and seem to be exactly the same site.

Installing java from Oracle (was Sun) -- 2011

The first step is to download the java packages from Oracle.
I used this link to fetch Java 1.7 on 9-26-2011.

You have to decide if you want the JRE (smaller, and what you want if you are not actually developing java applications) or the JDK (maybe 4 times bigger - but if you want to write java code to need this).

You also have to decide if you want an RPM or a binary package. Up to now I had always used the binary, but it really offers no advantage that I can see, so this time I grabbed the RPM. You also have to decide if you want the 64 bit x64 package or the 32 bit i586 package. I opted for the 64 bit package. After the package finished downloading I used:

rpm -Uvh jdk-7-linux-x64.rpm
rpm -Uvh jre-7-linux-x64.rpm
to install the packages (yes, I needlessly installed both).

The lions share of the files go to /usr/java/jre1.7.0

At this point if you type java -version you will discover that you are still running java from the OpenJDK, there is more to be done to switch from OpenJDK to Sun Java.

I found a lot of useful information on the following links:

In a nutshell, which java is actually used is managed by a bunch of links in /etc/alternatives. In particular, /usr/bin/java is a link to /etc/alternatives/java which is a link to whatever java thing ought to be run. You could fiddle with all these links by hand, but fedora provides a utility to take care of this. What you need to do is the following (for the JDK):

su
## java ##
alternatives --install /usr/bin/java java /usr/java/jdk1.7.0/jre/bin/java 20000
## javaws (32-bit only) ##
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0/jre/bin/javaws 20000
## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0/jre/lib/i386/libnpjp2.so 20000
## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0/jre/lib/amd64/libnpjp2.so 20000
## Install javac only if you installed JDK (Java Development Kit) package ##
alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0/bin/javac 20000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0/bin/jar 20000

For the JRE, do this:

su
## java ##
alternatives --install /usr/bin/java java /usr/java/jre1.7.0/bin/java 20000
## javaws (32-bit only) ##
alternatives --install /usr/bin/javaws javaws /usr/java/jre1.7.0/bin/javaws 20000
## Java Browser (Mozilla) Plugin 32-bit ##
alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jre1.7.0/lib/i386/libnpjp2.so 20000
## Java Browser (Mozilla) Plugin 64-bit ##
alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jre1.7.0/lib/amd64/libnpjp2.so 20000
Once this is done, you can verify that the proper things are getting run as follows:
java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
  
javaws
Java(TM) Web Start 1.7.0
  [...]
   
javac -version
javac 1.7.0

And, after doing this, you can much more conveniently select what java you want to run (just in case you want to switch back to using OpenJDK) by using:

alternatives --config java

To check what firefox is doing, restart firefox and then type about:plugins in the URL entry field.

Lastly, you will need to add one or the other of the following lines to your .bashrc

## export JAVA_HOME JDK ##
export JAVA_HOME="/usr/java/jdk1.7.0"
 
## export JAVA_HOME JRE ##
export JAVA_HOME="/usr/java/jre1.7.0"

Have any comments? Questions? Drop me a line!

Adventures in Computing / tom@mmto.org