Tuesday, June 24, 2008

Installing Sun's Java JRE and JDK on Fedora 5

So for the last couple of days, I've been trying to get Hadoop working on my computer at work, which runs Fedora. Monday (yesterday), I found out that the source of my troubles had to do with the fact that Hadoop requires Sun's Java. Fedora, by default, comes with Gnu's Java.This would be, in most cases, ok, as Gnu's Java mimics Sun's Java and has most of the same functionality. However, certain projects (like Hadoop) requires Sun's Java, so it's a good idea to try and have both on the system.

Installing Java on Fedora is a pain. No one guide online helped me successfully install the damn thing onto my work machine, which led to quite a bit of frustration. However, since things seem to be working correctly (finally!), I thought I would share my procedure with all of you who may have to do this at some point. Even though the majority of my code posts concern Ubuntu, I think this is a worthwhile diversion.

To install Java properly (for the coders out there), there are two steps: i.) The Java Run Time Environment (JRE) and ii.) The Java Developer's Kit (JDK). Most of the instructions I'm putting here is an amalgamation of instructions found on two sites, both of which had some instructions that worked for me, and others that did not.

----

Before we begin, Make sure your System is Completely Up to Date This is CRUCIAL. All the following instructions probably will not work properly if your Fedora install is not properly updated. One thing that slowed me down quite a bit is that I initially did not do this step.

INSTALLING THE JAVA RUNTIME ENVIRONMENT (JRE)

1. Enter root mode by typing in
su

While I imagine it is possible to install this stuff locally, having root access is ideal.

2. Make sure that your system has rpmdevtools and jpackage-utils. You can install these by typing:

yum -y install rpmdevtools
yum -y install jpackage-utils

3. Next grab the jpackage key and set up the jpackage repositories for yum

rpm --import http://jpackage.org/jpackage.asc
cd /etc/yum.repos.d
wget http://www.jpackage.org/jpackage17.repo

If SUCCESS, go to step 4.
If FAIL, check to make sure that you have wget installed. Install it using:
yum -install wget

4. Get the latest Jpackage java-x-sun-xjpp.nosrc.rpm package from the non-free branch at jpackage. The package I used was this one.
Install this file by typing something akin to the following (yours may be different based on version numbers)
./java-1.6.0-sun-1.6.0.6-1jpp.nosrc.rpm

If this works, you will see it installed under /usr/src/redhat/

If SUCCESS: go to step 5.
If FAIL: Check permissions. You may have to change permissions as follows:

chmod 755 java-1.6.0-sun-1.6.0.6-1jpp.nosrc.rpm

If SUCCESS, go to step 5.
If FAIL, I cannot help you. Sorry!

5. Get the latest binary. I got mine from here. It should look something like jre-6u6-linux-i586.bin.
Move this file to the SOURCES directory. So something like,

mv jre-6u6-linux-i586.bin /usr/src/redhat/SOURCES/.

Next, rebuild the java rpm using

rpmbuild -ba java-1.x.0-sun.spec

If SUCCESS, you should now be able to see the binary in /usr/src/redhat/RPMS/i586/ . Go to step 6.
If FAIL, make sure that you are running this command in the /usr/src/redhat/SPEC/ directory. If you do not have a spec file, you did something wrong in the previous steps, or I can't help you.

6. Install the binaries in /usr/src/redhat/RPMS/i586/ by using the following command:
yum --nogpgcheck localinstall java*.rpm

If SUCCESS, go on to part 2.
IF FAIL, the most likely reason for failure is some sort of message like --nogpgcheck not a valid command for yum. Omit it then. Alternatively, you can manually go into the /usr/src/redhat/RPMS/i586/ folder and install all the rpms by double clicking on them.


INSTALLING JDK

1. Make sure you have the following packages: rpm-build and fedora-rpmdevetools. If not, install using
yum install fedora-rpmdevtools
yum install rpm-build

2. Grab the sun jdk rpm file. I got mine from here. The file should look something like: jdk-6u6-linux-i586-rpm.bin

Run the rpm by doing the following:
chmod 755 jdk-6u2-linux-i586-rpm.bin
./jdk-6u2-linux-i586-rpm.bin

If SUCCESS, you should be able to see a whole bunch of RPMs located in /usr/java/jdk1.6.0_02 and a new directory in /opt/sun . Move to step 3

3. Next, install the RPM. You'll also need a compat file from Jpackages. I got mine here. It should look something like java-1.6.0-sun-compat-1.6.0.06-1jpp.src.rpm.

Do the following:
yum --enablerepo=jpackage-generic-nonfree install java-1.6.0-sun-compat-1.6.0.06-1jpp.src.rpm

Say yes when prompted. This should complete installation of JDK.

4. Keep in mind that the default Java may still not be Sun Java. To fix this, we need one last step:

/usr/sbin/alternatives --config java

This should show two options: GIJ (the older java) and Sun's Java. On my machine it was option 2. Enter the number that corresponds to the Sun Java install and press enter.

Now, if you type in:

java -version

It should print out something like:

java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06)
Java HotSpot(TM) Client VM (build 1.6.0_06, mixed mode, sharing)


You're done!

Additionally, you'll probably want to install the mozilla plugin. Do something akin to the following
ln -s /usr/lib/jvm/java-1.6.0-sun-1.6.0/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin_oji.so


And that should fix everything. Hope this post will eventually be helpful to someone. Comments welcome.

7 comments:

Ethan said...

Jesus, it can't really be that complicated, can it? On Debian it's just a matter of apt-getting sun-java6-jre and sun-java6-jdk (well, assuming you already enabled non-free). Maybe Sun has more user-friendly packages? I think at work our production servers run Red Hat, and my boss mentioned something about grabbing packages from Sun. Shrug..

Ethan

Suzanne said...

I didn't think it would be! Maybe there is a more direct approach... but I don't know if it.

I think the main issue is that gij comes installed on the system, and manually changing all the symbolic links is a pain, and may not be global, if you're not careful. So I'd want to use the alternatives utility. The problem was that if i didn't do it this way, alternatives would not detect the new Java install.

Of course, another part of the problem is that the Fedora system I have at work was not updated -at all- and I originally didn't realize that I had to download and install gdk in addition to jre. But those were relatively minor compared to that crap with alternatives. I'm pretty sure that if there was no other Java on this system, installation wouldn't have been nearly as complicated.

Anonymous said...

Really informative blog post here my friend. I just wanted to comment & say keep up the quality work. I’ve bookmarked your blog just now and I’ll be back to read more in the future my friend! Also well-chosen colors on the theme it goes well with the blog in my modest opinion :)

Anonymous said...

А! Ich normalerweise nicht in Blogs posten, aber Ihr Blog zwingt mich dazu, erstaunliche Arbeit .. schön ...

Suzanne said...

To my last two anonymous commentators:
Thank you very much :-) I am quite flattered.

To my German-speaking viewer:
While I do not know German, I was able to roughly translate your comment to:
"Ah! I don't normally comment in blogs but your blog made me, astonishing work.. beautiful." You made me blush :-)

Anonymous said...

Good writing here I thoroughly truly enjoy the manner you compose your pages . I will go on visiting your web site in the time to come to understand other fabulous blog contents like this one! This is an astounding publish here.

As a final point , let me thank you for your patience with my English as (I'm persuaded you have become aware this at this time ,), English is not my chief tongue consequently I am using Google Translate to build out how to note down what I really mean to write down .

Suzanne said...

You are very kind :) I'm glad that you enjoyed the piece. I have not updated this blog in a while (due to the pace of my graduate studies), but I am very happy that people are still finding its content useful.