8.25.2008

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.



STEP I: SYS PREP
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
Password:
# yum install -y rpm-build gcc gcc-c++ redhat-rpm-config
# yum -y install jpackage-utils
# su user_name
$



STEP II: INSTALL JAVA

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-1.6.0.7-1jpp.nosrc.rpm package
$ cd ~/rpmbuild
$ curl -L -O http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free/java-1.6.0-sun-1.6.0.7-1jpp.nosrc.rpm
$ rpmbuild --rebuild java-1.6.0-sun-1.6.0.7-1jpp.nosrc.rpm
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-1.6.0.7-1jpp.i586.rpm
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-1.6.0.7-1jpp.i586.rpm

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 ....."

8 comments:

Anonymous said...

THANKS!!!

Unknown said...

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

Anonymous said...

javaBuild --rebuild java-1.6.0-sun-1.6.0.7-1jpp.nosrc.rpm

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

skyMyrka said...

Thanks for catching my mistake.
Should be
rpmbuild --rebuild java-1.6.0-sun-1.6.0.7-1jpp.nosrc.rpm

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

skyMyrka 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-1.6.0.7-1jpp.nosrc.rpm cannot be installed


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

Anonymous said...

Thanks for work around. Works.

Ken Anderson said...

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

http://www.watermarkstudios.com/blog/?p=13

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/