Installing Java (Sun JDK 1.6.0) on CentOS 5

This is a quick and dirty guide to installing java on CentOS5.

NOTE: do not log in as root to perform this installation, but you will need credentials with su command. During install, substitute 'user_name' with your login handle.

1. Open terminal

2. Set up working directories (in this example it's ~/rpmbuild)

$ mkdir -p ~/rpmbuild/{SOURCES,SRPMS,SPECS,RPMS,tmp,BUILD}

3. Create ~/.rpmmacros

$ echo "%_topdir /home/user_name/rpmbuild" >> .rpmmacros
$ echo "%_tmppath %{_topdir}/tmp" >> .rpmmacros

4. Log in as root and use YUM to install following packages
$ su root
# yum install -y rpm-build gcc gcc-c++ redhat-rpm-config
# yum -y install jpackage-utils
# su user_name


1. Download JDK 1.6 update 7 self-extracting RPM version (jdk-6u7-linux-i586.bin) from Sun to ~/rpmbuild/SOURCES/

2. Download and build java-1.6.0-sun- package
$ cd ~/rpmbuild
$ curl -L -O http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free/java-1.6.0-sun-
$ rpmbuild --rebuild java-1.6.0-sun-
don't get freaked out by the errors or that it could take a little while, it's ok. Verify that RPMS directory in rpmbuild contains i586 directory with rpms.

3. su to root and migrate rpms to local yum repository

# yum localinstall ~user_name/rpmbuild/RPMS/i586/java-1.6.0-sun-
NOTE: if you get "NOT SIGNED" issue (and most likely you will), resolve by the following work-around
- install X11 library to resolve libXP.so.6 dependency
# yum install libXp-devel.i386
- then plain old rpm
# rpm -Uvh ~user_name/rpmbuild/RPMS/i586/java-1.6.0-sun-

4. Login as root to configure alternatives system to use new JDK
[root@blah]# alternatives --config java

5. Verify install
$ java -version
it should display java version "1.6.0_07 ....."


Anonymous said...


Zheng said...

Thank you! I got the "NOT SIGNED" issue resolved by using your work-around!

Anonymous said...

javaBuild --rebuild java-1.6.0-sun-

That command doesn't work... any help?

de0ris said...

Thanks for catching my mistake.
Should be
rpmbuild --rebuild java-1.6.0-sun-

I've made the correction to the post.
Should work now.

de0ris said...

I got some msgs about this, so...
If you get the following error during the install:

warning: InstallSourcePackage: Header V3 DSA signature: NOKEY, key ID .......
error: cannot create %sourcedir /home/user_name/rpmbuild/SOURCES

error: java-1.6.0-sun- cannot be installed

You have not setup .rpmmacros correctly. Hint: you may have neglected to replace user_name with your actual user name.

Simon said...

Thanks for work around. Works.

Ken Anderson said...

Here is a very simple walk-through for installing JDK:


Anonymous said...

I couldn't get this to work but this set of instructions worked straight away, - http://chrisschuld.com/2008/10/installing-sun-java-on-centos-5-2/