How to install Sun Java JDK 1.6 update 14 on Centos 5.3

If you are a Linux system administrator, you may face this issue frequently: How to install Sun JDK on the Linux Server? Why the one comes with Linux system is not a full version of Sun JDK? Don’t spend too much time figuring out the licensing issues, and let us have a look how to deal with this problem.

To sum up, we need to rebuild the JDK ourselves. Follow the steps below:

  1. Assume you are root now, install required packages:
    yum install -y rpm-build gcc gcc-c++ redhat-rpm-config jpackage-utils
  2. Create a user to do the rebuilding work (root is considered as evil when doing the rebuild):
    useradd rpmbuilder
    passwd rpmbuilder
  3. Switch from root to user rpmbuilder
    su - rpmbuilder
  4. Create a .rpmmacros file in /home/rpmbuilder/ folder with content as below, adjust when using different username:
    %_topdir /home/rpmbuilder/rpmbuild
    %_tmppath %{_topdir}/tmp
  5. Create rpm building folder tree in /home/rpmbuilder folder
    mkdir -p ~/rpmbuild/{SOURCES,SRPMS,SPECS,RPMS,tmp,BUILD}
  6. Download Sun JDK 1.6 update 14 (this archive link will help you find the download link)
    cd ~/rpmbuild/SOURCE
    wget http://cds.sun.com/....../jdk-6u14-linux-i586.bin
    mv <long file name you just downloaded> jdk-6u14-linux-i586.bin
  7. Donwload JPackage SRPMS.non-free jpp.nosrc.rpm (version must match, in this example it is 1.6.0.14)
    cd ~/rpmbuild
    wget ftp://jpackage.hmdc.harvard.edu/JPackage/6.0/generic/SRPMS.non-free/java-1.6.0-sun-1.6.0.14-1jpp.nosrc.rpm
  8. Now it is time to rebuild the package
    cd ~/rpmbuild
    rpmbuild --rebuild java-1.6.0-sun-1.6.0.14-1jpp.nosrc.rpm
  9. Switch back to root and install the package under ~/rpmbuild/RPMS/i586
    rpm -ihv java-1.6.0-sun-1.6.0.14-1jpp.i586.rpm
  10. The rest is to configure your ‘alternative java’
    alternatives –config java
  11. Testing
    java -version