HowTo Install Java on CentOS 4 and CentOS 5

1. Preliminary material

The Sun license concerning distribution of Java (through to Java 6) contains clauses, the terms of which, the CentOS team have concluded they cannot meet. Conversations with Sun's representatives on a modified distribution license were underway in August 2008 but they did not yield fruit. Seemingly Sun was looking forward to the more free, later, Java releases (on the horizon, upstream) in our upstream's Fedora project.

SPECIAL NOTE: Starting with CentOS 5.3 the upstream source for SRPMs, which the project rebuilds into the base and updates repositories, has added the openjdk product into the freely available sources as part of its distribution. As such, the CentOS project can now ship an integrated Java implementation. Using this approach can greatly simplify installation matters and we encourage you to consider using the proper subset from the following newly provided packages & filing bugs upstream, if problems are noted.

[user@host ~]$ sudo yum list \*java-1\* | grep open 
java-1.6.0-openjdk.x86_64                 1:1.6.0.0-0.25.b09.el5       base
java-1.6.0-openjdk-demo.x86_64            1:1.6.0.0-0.25.b09.el5       base
java-1.6.0-openjdk-devel.x86_64           1:1.6.0.0-0.25.b09.el5       base
java-1.6.0-openjdk-javadoc.x86_64         1:1.6.0.0-0.25.b09.el5       base
java-1.6.0-openjdk-src.x86_64             1:1.6.0.0-0.25.b09.el5       base
[user@host ~]$

Additionally, some fonts are required by applications using the AWT and a representative list follows:

[user@host ~]$ rpm -qa \*fonts\* 
ghostscript-fonts-5.50-13.1.1
xorg-x11-fonts-base-7.1-2.1.el5
xorg-x11-fonts-Type1-7.1-2.1.el5
xorg-x11-fonts-75dpi-7.1-2.1.el5
bitmap-fonts-0.3-5.1.1
urw-fonts-2.3-6.1.1
xorg-x11-fonts-ISO8859-1-75dpi-7.1-2.1.el5
xorg-x11-fonts-100dpi-7.1-2.1.el5
xorg-x11-fonts-truetype-7.1-2.1.el5
xorg-x11-fonts-ISO8859-15-75dpi-7.1-2.1.el5
dejavu-lgc-fonts-2.10-1
bitstream-vera-fonts-1.10-7
xorg-x11-fonts-ISO8859-15-100dpi-7.1-2.1.el5
xorg-x11-fonts-ISO8859-1-100dpi-7.1-2.1.el5
liberation-fonts-1.0-1.el5
[user@host ~]$ 

If you feel that the Sun (or another implementation is needed), a manual installation and acceptance of the install-time license may be required. This page outlines two methods for doing so. Most of the operations may be performed as a normal user and a command line prompt of $ is used to indicate this. When root powers are required, a command line prompt of # shown. Sadly, these methods are not as well integrated with the alternatives of the CentOS 5.3 and later approach.

Two methods are outlined here -- Method One, which is not designed to attempt to work with the jpackage.org method and Method Two, which should work, but 'rots' over time as Sun issues new Java versions.

2. Method One: 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-fc6), and 1.6 (jdk-1.6.0_07-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.

<!> Sadly, this method is not compatible with the CentOS 5 'tomcat5' package needs; a simple 'yum -y install tomcat5 httpd' has been reported as providing that, however.

3. Method Two: A less simple approach

Co-Author: MikaelFridh

<!> The following wiki section section needs a maintainer, as it is not actively maintained as of 11 Oct 2007. <!> JDK 1.6 section updated and verified by MikaelFridh 11 Jul 2008.

*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).

3.1. Java for the desktop user

There are two very simple methods of getting Java to run inside the webbrowser and to run java applications.

3.1.1. Using icedtea (CentOS 6 only)

Simply install icedtea-web using yum:

[user@host ~]$ yum install icedtea-web 

After restarting your browser Java should work for most applications. The java verification applet (link provided at the bottom of this page) works fine. More information on icedtea can be found here.

3.1.2. Using Oracle JRE

Another very simple way to have a Java Virtual Machine installed is to download the latest JDK from Oracle 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.

If only the runtime environment and browser plugins are required see How to install the Java Runtime Environment (JRE) from Java.com and configure plugins.

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

3.3. Requirements

It is assumed that the reader understands:

3.4. 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 Yum and RPM 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. Please, for the safety of your system's installed packages, be safe, and build only as a non-root user.

For this example, it will be assumed that the contents of ~/.rpmmacros includes:

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

Remember to create the ~/rpmbuild/ tree if it has not been created yet, but be aware that your directory is not required to be named "rpmbuild" as in this example (consult your ~/.rpmmacros to know):

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

Before building, the build environment needs to be complete. Some needed packages are:

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

Note that the installation of these packages only is done as root.

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

3.5.1. A. Sun JDK 1.4.2

Tested on: CentOS 4.7 and CentOS 5.2.

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, the latest Sun JDK 1.4.2 for which there is a corresponding JPackage source RPM is 1.4.2 update 17. Download J2SE v1.4.2_17 SDK from http://java.sun.com/j2se/1.4.2/download.html (or from the Sun JDK archive page if a newer 1.4 JDK has been released). 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_17-linux-i586.bin. After downloading, put the file inside ~/rpmbuild/SOURCES/ :

$ mv j2sdk-1_4_2_17-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.17-1jpp.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.17-1jpp.nosrc.rpm

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

java-1.4.2-sun-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-alsa-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-demo-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-devel-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-fonts-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-jdbc-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-plugin-1.4.2.17-1jpp.i586.rpm
java-1.4.2-sun-src-1.4.2.17-1jpp.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.17-1jpp.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 the Java:

$ java -version

You should get a reply similar to:

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

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

3.5.2. 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 IBM Java distribution site (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). Note that this name will change over time; make the needed changes in the file name after inspecting that directory with a web browser.

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 a reply similar to:

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))

3.5.3. C. Sun JDK 1.5

Tested on: CentOS 4.7 and CentOS 5.2.

Download the file java-1.5.0-sun-1.5.0.15-1jpp.nosrc.rpm (which is tested to work 15 Nov 2008). Again, as time passes, and new releases occur, the exact name will vary; use a web browser to inspect the directory for the current name.

Download Sun JDK 1.5 update 15 from the Sun JDK archive page. Make sure you download the "self-extracting file", not the "RPM in self-extracting file", and choose the correct architecture ("Linux" for the 32-bit, "i586" or "Linux x64" for the 64-bit, "x86_64" variant). The instructions below are for the 32-bit JDK/JRE:s. (The 64-bit Sun JDK file has a name that ends in "-amd64.bin" and doesn't have the browser plugin, and thus, the -plugin rpm won't be built)

Move the file into ~/rpmbuild/SOURCES

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

Make that .bin file executable with: chmod +x ~/rpmbuild/SOURCES/jdk-1_5_0_15-linux-i586.bin

Now, build the packages:

$ rpmbuild --rebuild java-1.5.0-sun-1.5.0.15-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.15-1jpp.i586.rpm
java-1.5.0-sun-alsa-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-demo-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-devel-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-fonts-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-jdbc-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-plugin-1.5.0.15-1jpp.i586.rpm
java-1.5.0-sun-src-1.5.0.15-1jpp.i586.rpm

Optionally, you may now delete the file java-1.5.0-sun-1.5.0.15-1jpp.nosrc.rpm

Install the RPMs as user root. To get the JRE and web browser plugin, do as follows:

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

In order to develop Java programs, you'll need the -devel package aswell:

# rpm -Uvh java-1.5.0-sun-devel-1.5.0.15-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_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
Java HotSpot(TM) Client VM (build 1.5.0_15-b04, mixed mode, sharing)

3.5.4. 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 the 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

3.5.5. E. Sun JDK 1.6

Tested on: CentOS 4.7 and 5.2

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

Make sure you've set up your rpm build environment as outlined in 3.4. Step 1. Initial setup

# 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 jpackage-utils

Download Sun JDK 1.6 update 14 from Sun Java download or the Sun JDK archive. Choose the correct platform (Linux or Linux x64) and download either jdk-6u14-linux-i586.bin or jdk-6u14-linux-x64.bin. Place it in your ~/rpmbuild/SOURCES directory.

Example:

$ cd ~/rpmbuild/SOURCES
$ curl -L -O 'http://very-long-sun-url-copied-from-sun-download-pages'

Browse the JPackage archive for the proper nosrc.rpm file. At the time of writing it is: java-1.6.0-sun-1.6.0.14-1jpp.nosrc.rpm

$ cd ~/rpmbuild/
$ curl -L -O http://mirrors.dotsrc.org/jpackage/5.0/generic/SRPMS.non-free/java-1.6.0-sun-1.6.0.14-1jpp.nosrc.rpm

Rebuild the packages:

$ rpmbuild --rebuild java-1.6.0-sun-1.6.0.14-1jpp.nosrc.rpm

<!> On this particular test system, the brp-java-repack stage took a very long time and there were some unzip errors saying that US_export_policy.jar and local_policy.jar where broken. Build finishes anyway.

You'll end up with a bunch of rpms:

Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-devel-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-src-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-demo-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-plugin-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-fonts-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-alsa-1.6.0.14-1jpp.i586.rpm
Wrote: /home/mikaelf/rpmbuild/RPMS/i586/java-1.6.0-sun-jdbc-1.6.0.14-1jpp.i586.rpm

Put them in your local yum repository or install them:

# yum --nogpgcheck localinstall ~/rpmbuild/RPMS/i586/java-1.6.0-sun-1.6.0.14-1jpp.i586.rpm

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

# alternatives --config java
There is 1 program that provides 'java'.
  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-sun/bin/java
Enter to keep the current selection[+], or type selection number:

Then try to execute Java:

$ java -version

You should get:

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

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

4. Other Tools

A web browser java installation testing tool is here.

5. Administrivia

'Java' is asserted to be a trademark of Sun/Oracle, and when it is used in a context of that mark, we have capitalized it; when used as a program, however, it is called: java

HowTos/JavaOnCentOS (last edited 2012-05-24 09:41:46 by TimothyLee)