HowTo Install Java on CentOS 4 and CentOS 5

A simple approach

Author: RussHerrold

A simple and lightweight approach, for people needing less than the full Jpackage approach (described below), is to install Java, getting it working for the browser, and for running prebuilt the Sun Java .jar's. This is described at the Trading Shim site.

Any one of Sun's Java 1.4 (j2sdk-1.4.2_15-fcs), 1.5 (jdk-1.5.0_12-fcs), and 1.6 (jdk-1.6.0_03-fcs)[called at Sun: Java(TM) SE Development Kit 6] offerings may all be installed and enabled using those instructions, and have each been tested and work. The JDK 1.5 and 1.6 are used daily on CentOS 4 and CentOS 5 series installations.

A less simple approach

Maintainer: LeonardoPinheiro

<!> The following wiki section section needs a maintainer, as it is not actively maintained as of 11 Oct 2007.

*This HowTo is not complete yet. There is a report that the following part of this writeup is outdated in the IRC channel on 27 July 2007

There are several ways to get a Java Virtual Machine installed on CentOS 4 or 5. The requirements for having a "Java environment" are different between servers and desktop users. Often desktop users need Java only to execute a few programs (including Java applets inside Mozilla Firefox).

Java for the desktop user

The simplest way to have a Java Virtual Machine installed is to download the latest JDK from Sun in the form "RPM in self-extracting file", run the self-extracting file and then install manually the provided RPM. This may be good enough for desktop users.

If you need Java for the desktop computer, you don't need to follow the steps described in this document.

Java for the developer and the server environment

However, servers may rely heavily on packages provided by third party repositories (like JPackage), therefore it's necessary to assure that those third party programs are going to find the JDK, and other packages they depend on, in predictable places, in a coherent and consistent tree. The JDK RPMs and binaries provided by Sun and IBM don't provide exactly what is desired for this purpose, so there is a need for reshaping those JDK when it is possible (rebuilding the -nosrc RPMs) or using compatibility packages (using the -compat RPMs). Whenever possible, you should prefer the -nosrc way. The processes of rebuilding the -nosrc and deploying the -compat are depicted in this document.

This document shows the process of installing JDK versions 1.4.2, 1.5.0 and 1.6.0, from either Sun and IBM, using the JPackage repository.

In the end, the user should be able to install several JDK versions and alternate between them with the command 'alternatives'.

If you are a developer on the Java language or you run servers, you shall use the method described in this document to install Java and use JPackage repository.

Requirements

It is required that the reader understands:

Step 1. Initial setup

Set up ~/.rpmmacros. If you don't know what this is, just use the example below, replacing <username> by your Linux user name.

If you haven't read http://wiki.centos.org/TipsAndTricks/YumAndRPM yet, remember it is a pre-requisite for using this HowTo.

Remember: the ~/.rpmmacros and the build tree should never be made with the root user.

As an example, it will be assumed that the contents of ~/.rpmmacros is:

%_topdir /home/<username>/rpmbuild
%_tmppath %{_topdir}/tmp

Don't forget to create the rpmbuild tree if it has not been created yet, but be aware that your directory may not be "rpmbuild" like this example (read your ~/.rpmmacros to know):

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

Make sure some nedded packages are installed (as root):

yum install -y rpm-build gcc gcc-c++ redhat-rpm-config

Step 2. Installing your favorite JDK

Choose your favorite JDK vendor and version:

A. Sun JDK 1.4.2

B. IBM JDK 1.4.2

C. Sun JDK 1.5.0

D. IBM JDK 1.5.0

E. Sun JDK 1.6.0

From now on, be sure to be logged as a user, not as root.

A. Sun JDK 1.4.2

Tested on: CentOS 4.4 and CentOS 5.0.

I recommend that only experts try to install this JDK, because there may be dependencies issues. A workaround is to install Sun JDK 1.5.0 before Sun JDK 1.4.2.

At the time of this writing, Sun JDK 1.4.2 last update release is 1.4.2_14. Download J2SE v1.4.2_14 SDK from http://java.sun.com/j2se/1.4.2/download.html. Make sure you download the "self-extracting file", not the "RPM in self-extracting file", and choose the correct architecture (IA64 for Itanium processor or i586 otherwise). The file name is j2sdk-1_4_2_14-linux-i586.bin. After downloading, put the file inside ~/rpm/SOURCES/:

mv j2sdk-1_4_2_14-linux-i586.bin ~/rpmbuild/SOURCES/

Take a look at http://mirrors.dotsrc.org/jpackage/1.7/generic/SRPMS.non-free and choose an appropriate version for the java-1.4.2-sun-X*Z.nosrc.rpm. At the time of this writing, it is java-1.4.2-sun-1.4.2.14-2jpp.nosrc.rpm. Download the file, then go to the directory where you saved the file java-1.4.2-sun-X*Z.nosrc.rpm. and build the packages:

rpmbuild --rebuild java-1.4.2-sun-1.4.2.14-2jpp.nosrc.rpm

In the end, the following files will have been created inside ~/rpmbuild/RPMS/i586:

java-1.4.2-sun-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-alsa-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-demo-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-devel-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-fonts-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-jdbc-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-plugin-1.4.2.14-2jpp.i586.rpm
java-1.4.2-sun-src-1.4.2.14-2jpp.i586.rpm

Try to install the RPMs as user root:

su -
cd /home/<username>/rpmbuild/RPMS/i586
yum install java-1.4.2-sun-1.4.2.14-2jpp.i586.rpm

Configure the Alternatives system and choose the JDK you want (run as root):

alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           /usr/lib/jvm/jre-1.5.0-sun/bin/java
*  2           /usr/lib/jvm/jre-1.6.0-sun/bin/java
   3           /usr/lib/jvm/jre-1.5.0-ibm/bin/java
   4           /usr/lib/jvm/jre-1.4.2-sun/bin/java

Enter to keep the current selection[+], or type selection number: 4

Then try to execute java:

java -version

You should get:

java version "1.4.2_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_14-b05)
Java HotSpot(TM) Client VM (build 1.4.2_14-b05, mixed mode)

The other RPMs generated in the process may also be installed as long as they are needed:

B. IBM JDK 1.4.2

Tested on: CentOS 4.4 and CentOS 5.0.

At the time of this writing, the last update release of IBM JDK 1.4.2 is update 8, and the file you should obtain is IBMJava2-SDK-1.4.2-8.0.tgz (Intel Compatible) from http://www-106.ibm.com/developerworks/java/jdk/linux140/ (registration at IBM site is required).

After downloading, rename the file to IBMJava2-SDK-142.tgz and put it under ~/rpmbuild/SOURCES:

mv IBMJava2-SDK-1.4.2-8.0.tgz ~/rpmbuild/SOURCES/IBMJava2-SDK-142.tgz

Download the file http://mirrors.dotsrc.org/jpackage/1.7/generic/non-free/RPMS/java-1.6.0-sun-compat-1.6.0.01-1jpp.i586.rpm (which is reported to work as of 11 Oct 2007)

Build the packages:

rpmbuild --rebuild java-1.4.2-ibm-1.4.2.3-1jpp.nosrc.rpm

If everything was ok, the following RPMs are created inside ~/rpmbuild/RPMS/i386:

java-1.4.2-ibm-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-alsa-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-demo-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-devel-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-fonts-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-jdbc-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-plugin-1.4.2.3-1jpp.i386.rpm
java-1.4.2-ibm-src-1.4.2.3-1jpp.i386.rpm

Install the RPMs as user root:

su -
Password: <type root password>
cd /home/<username>/rpmbuild/RPMS/i386
rpm -Uvh java-1.4.2-ibm-1.4.2.3-1jpp.i386.rpm
rpm -Uvh java-1.4.2-ibm-alsa-1.4.2.3-1jpp.i386.rpm
rpm -Uvh java-1.4.2-ibm-jdbc-1.4.2.3-1jpp.i386.rpm

Configure the Alternatives system and choose the JDK you want (run as root):

alternatives --config java

Then try to execute java:

java -version

You should get:

java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2)
Classic VM (build 1.4.2, J2RE 1.4.2 IBM build cxia32142-20070321 (SR8) (JIT enabled: jitc))

C. Sun JDK 1.5

Tested on: CentOS 4.4 and CentOS 5.0.

Download the file [http://mirrors.dotsrc.org/jpackage/1.7/generic/non-free/SRPMS/java-1.5.0-sun-1.5.0.13-1jpp.nosrc.rpm http://mirrors.dotsrc.org/jpackage/1.7/generic/non-free/SRPMS/java-1.5.0-sun-1.5.0.13-1jpp.nosrc.rpm] (which is reported to work 11 Oct 2007)

Download Sun JDK 1.5 update 11 from http://java.sun.com/javase/downloads/index_jdk5.jsp. Make sure you download the "self-extracting file", not the "RPM in self-extracting file", and choose the correct architecture (IA64 for Itanium processor or i586 otherwise).

Move the file into ~/rpmbuild/SOURCES

mv jdk-1_5_0_13-linux-i586.bin ~/rpmbuild/SOURCES

Build the packages:

rpmbuild --rebuild java-1.5.0-sun-1.5.0.13-1jpp.nosrc.rpm

In the end, if everything was ok, some rpms are created inside ~/rpmbuild/RPMS/i586:

java-1.5.0-sun-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-alsa-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-demo-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-devel-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-fonts-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-jdbc-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-plugin-1.5.0.13-1jpp.i586.rpm
java-1.5.0-sun-src-1.5.0.13-1jpp.i586.rpm

You may remove the file java-1.5.0-sun-1.5.0.13-1jpp.nosrc.rpm

Install the RPMs as user root:

su -
cd /home/<username>/rpmbuild/RPMS/i586
rpm -Uvh java-1.5.0-sun-1.5.0.13-1jpp.i586.rpm
rpm -Uvh java-1.5.0-sun-alsa-1.5.0.13-1jpp.i586.rpm
rpm -Uvh java-1.5.0-sun-plugin-1.5.0.13-1jpp.i586.rpm

Configure the Alternatives system and choose the JDK you want (run as root):

alternatives --config java

Then try to execute java:

java -version

You should get:

java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

D. IBM JDK 1.5

Tested on: CentOS 4.4.

Download the file http://mirrors.dotsrc.org/jpackage/1.7/generic/non-free/SRPMS/java-1.5.0-ibm-1.5.0.2.3-3jpp.nosrc.rpm

Download IBM JDK 1.5 (tgz format, not rpm) from http://www-128.ibm.com/developerworks/java/jdk/linux/download.html (registration is required). Download from the same place the Java Communication API.

Rename the file names and put them under ~/rpmbuild/SOURCES/

mv ibm-java2-sdk-5.0-4.0-linux-i386.tgz ~/rpmbuild/SOURCES/ibm-java2-sdk-50-linux-i386.tgz
mv ibm-java2-javacomm-5.0-4.0-linux-i386.tgz ~/rpmbuild/SOURCES/ibm-java2-javacomm-50-linux-i386.tgz

Build the RPMs:

rpmbuild --rebuild java-1.5.0-ibm-1.5.0.2.3-3jpp.nosrc.rpm

Install the RPMs:

su -
cd ~/rpmbuild/RPMS/i386
rpm -Uvh java-1.5.0-ibm-*.rpm

Configure the Alternatives system and choose the JDK you want (run as root):

alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           /usr/lib/jvm/jre-1.5.0-sun/bin/java
*  2           /usr/lib/jvm/jre-1.6.0-sun/bin/java
   3           /usr/lib/jvm/jre-1.5.0-ibm/bin/java


Enter to keep the current selection[+], or type selection number: 3

Then try to execute java:

java -version

You should get:

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pxi32dev-20070201 (SR4))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20070201 (JIT enabled)
J9VM - 20070131_11312_lHdSMR
JIT  - 20070109_1805ifx1_r8
GC   - 200701_09)
JCL  - 20070126

E. Sun JDK 1.6

Tested on: CentOS 4.4 and 5.0.

If you are using CentOS 4, first install the JPackage's package 'jpackage-utils' (version 1.7b). Download the latest jpackage-utils RPM from http://mirrors.dotsrc.org/jpackage/1.7/generic/free/RPMS/ and install:

rpm -Uvh jpackage-utils-1.7.3-1jpp.noarch.rpm

If you're using CentOS 5, the package 'jpackage-utils' is available on the standard repositories:

yum install -y jpackage-utils

Download Sun JDK 1.6 update 1 from http://java.sun.com/javase/downloads/index.jsp. Make sure you download the "RPM in self-extracting file", and choose the correct architecture (IA64 for Itanium processor or i586 otherwise). The file name is jdk-6u1-linux-i586-rpm.bin. After downloading, make the file executable and run it:

chmod +x jdk-6u1-linux-i586-rpm.bin
./jdk-6u1-linux-i586-rpm.bin

Accept the license agreement, if you want to. Then it will extract the file jdk-6u1-linux-i586.rpm. Download the file http://mirrors.dotsrc.org/jpackage/1.7/generic/non-free/RPMS/java-1.6.0-sun-compat-1.6.0.01-1jpp.i586.rpm. Install both RPMs:

rpm -Uvh jdk-6u1-linux-i586.rpm java-1.6.0-sun-compat-1.6.0.01-1jpp.i586.rpm

Configure the Alternatives system and choose the JDK you want (run as root):

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-sun/bin/java

Enter to keep the current selection[+], or type selection number: 2

Then try to execute java:

java -version

You should get:

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

Step 3. Install the JPackage repository (CentOS 4 only - this step is optional, not finished)

At the time of this writing, the JPackage version is 1.7b.

Install the JPackage GPG key:

rpm --import http://www.jpackage.org/jpackage.asc

Download the JPackage reposity configuration file and install in /etc/yum.repos.d/

cd /etc/yum.repos.d/
wget http://jpackage.org/jpackage.repo

Edit the file jpackage.repo and enable jpackage-generic, jpackage-rhel and jpackage-generic-nonfree fields. Make sure your file looks like this one, mainly on the 'enabled=' lines:

[jpackage-generic]
name=JPackage (free), generic
mirrorlist=http://www.jpackage.org/jpackage_generic.txt
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=1

[jpackage-fc]
name=JPackage (free) for Fedora Core $releasever
mirrorlist=http://www.jpackage.org/jpackage_fedora-$releasever.txt
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=0

[jpackage-rhel]
name=JPackage (free) for Red Hat Enterprise Linux $releasever
mirrorlist=http://www.jpackage.org/jpackage_rhel-$releasever.txt
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=1

[jpackage-generic-nonfree]
name=JPackage (non-free), generic
mirrorlist=http://www.jpackage.org/jpackage_generic_nonfree.txt
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=1

Install the package jpackage-utils:

yum install -y jpackage-utils

HowTos/JavaOnCentOS (last edited 2007-10-11 18:21:38 by RussHerrold)