Skip to content

Sun Java for CentOS 5

Unfortunately the GNU java in CentOS 5 is too old to run modern Java code. So, you need to install the Sun version in many cases, and the jpackage method is typically the best way to do that. Two problems, though:
* They don’t have an RPM that represents the current Sun version
* Their version doesn’t work well on CentOS due to CentOS RPM bugs

If you don’t have them already installed, you need the RPM development tools. Something like:

yum -y install rpm-build rpmdevtools

should be sufficient. (note: I’m assuming you’re root. Most of this can also be done with a local RPM build tree and sudo, but is beyond the scope of this article).

As of this writing the current security release of the Java JDK is 1.6u7, which you can get here. Pick 32-bit linux (the only type I tested) get the linux non-RPM version, and put the downloaded ‘.bin’ file in /usr/src/redhat/SOURCES.

Now, download my updated spec file and put it in /usr/src/redhat/SPEC. If you’re on a Fedora platform or CentOS fixes their version of rpm you might want this non-CentOS spec instead. This latter one builds everything just fine on CentOS but there are UnixODBC link errors due to the rpm bug.

Now, build Java with:

cd /usr/src/redhat
rpmbuild -ba SPEC/java-1.6.0-sun-centos-5.spec

This will take a while. You should wind up with a bunch of RPM files in RPMS/i586/, like this:

-rw-r--r-- 1 root root 43085836 Aug 11 22:48 java-1.6.0-sun-
-rw-r--r-- 1 root root    35903 Aug 11 22:48 java-1.6.0-sun-alsa-
-rw-r--r-- 1 root root 10473773 Aug 11 22:48 java-1.6.0-sun-demo-
-rw-r--r-- 1 root root 21709383 Aug 11 22:48 java-1.6.0-sun-devel-
-rw-r--r-- 1 root root  1259794 Aug 11 22:48 java-1.6.0-sun-fonts-
-rw-r--r-- 1 root root    26057 Aug 11 22:48 java-1.6.0-sun-jdbc-
-rw-r--r-- 1 root root   807126 Aug 11 22:48 java-1.6.0-sun-plugin-
-rw-r--r-- 1 root root 17692845 Aug 11 22:48 java-1.6.0-sun-src-

Use yum to install them like this:

cd RPMS/i586
yum --nogpgcheck localinstall java-1.6.0-sun-*.rpm

It should find dependencies, something like this:

Dependencies Resolved

 Package                 Arch       Version          Repository        Size
 java-1.6.0-sun-alsa     i586     java-1.6.0-sun-alsa-   79 k
 java-1.6.0-sun-demo     i586     java-1.6.0-sun-demo-   15 M
 java-1.6.0-sun-devel    i586     java-1.6.0-sun-devel-   36 M
 java-1.6.0-sun-fonts    i586     java-1.6.0-sun-fonts-  2.0 M
 java-1.6.0-sun-jdbc     i586     java-1.6.0-sun-jdbc-   69 k
 java-1.6.0-sun-plugin   i586     java-1.6.0-sun-plugin-  1.6 M
 java-1.6.0-sun-src      i586     java-1.6.0-sun-src-   18 M
Installing for dependencies:
 java-1.6.0-sun          i586     java-1.6.0-sun-   68 M
 libXp                   i386       1.0.0-8.1.el5    base               23 k
 unixODBC-devel          i386       2.2.11-7.1       base              739 k
 unixODBC                i386       2.2.11-7.1       base              832 k

And yum should download and complete without errors.

Now, make sure that this new version of Java is set to be the default with:

/usr/sbin/alternatives --config java

and enjoy current java. Hopefully it won’t be long before Sun gets its code freed so next time you can just ‘yum -y install sun-java’.

5 thoughts on “Sun Java for CentOS 5”

  1. Richard Sharpe


    I tried the above steps, but I always get the following when trying to build (btw, I think it might be SPECS not SPEC):

    rpmbuild -ba SPECS/java-1.6.0-sun-centos-5.spec
    Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.51692
    + umask 022
    + cd /usr/src/redhat/BUILD
    + rm -rf /usr/src/redhat/BUILD/jdk1.6.0_07
    + export MORE=10000
    + MORE=10000
    + sh /usr/src/redhat/SOURCES/jdk-6u7-linux-x64.bin
    replace jdk-6u7-linux-amd64.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: NULL
    (assuming [N]one)
    package jdk-1.6.0_07-fcs is already installed
    + cd /usr/src/redhat/BUILD
    + cd jdk1.6.0_07
    /var/tmp/rpm-tmp.51692: line 28: cd: jdk1.6.0_07: No such file or directory
    error: Bad exit status from /var/tmp/rpm-tmp.51692 (%prep)

    RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.51692 (%prep)

    This suggests that the .bin file I have is not creating the directory jdk1.6.0_07 or something.

    Any ideas what is going wrong?

  2. Richard Sharpe

    OK, got this:

    Error: Missing Dependency: is needed by package java-1.6.0-sun-jdbc

  3. Richard Sharpe

    OK, it doesn’t matter if I build with or without the CentOS specific SPEC file. I get the same problem each time with the bogus required …

    Maybe I need to remove them?

  4. Richard Sharpe

    Finally got them installed with

    * rpm -Uvh –nodeps java*.rpm

    I don’t care about ODBC, I just want to run the Fedora/CentOS directory services admin tool.

Comments are closed.