It’s pretty easy to install Java on Linux - download the RPM from sun and install it. Then if you run “java -version” you’ll suddenly discover that it doesn’t really work:
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20070626 (Red Hat 4.1.2-14)
You can get around that by setting your path and JAVA_HOME, or by only using Java version that have a matching JPackage RPM and using the alternatives command
If you want to be able to build your own RPM, here’s how to do it.
- cat /etc/redhat-release - this is tested on CentOS release 5 (Final). It should work elsewhere, but… yeah… good luck with that. - Download the non-rpm Linux build from of java Sun. The filename will be something like jdk-6u11-linux-i586.bin. I’ve only tried this with the 32 bit build. - Download the jpackage17.repo file from jpackage.org. Currently this is availabel from http://www.jpackage.org/cgi-bin/viewvc.cgi/website/htdocs/jpackage17.repo?revision=1.1&root=jpackage&view=markup but the contents looks like this:
# Be sure to enable the distro specific repository for your distro below:
# - jpackage-fc for Fedora Core
# - jpackage-rhel for Red Hat Enterprise Linux and derivatives
[jpackage-generic]
name=JPackage (free), generic
mirrorlist=http://www.jpackage.org/mirrorlist.php?dist=generic&type=free&release=1.7
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/mirrorlist.php?dist=fedora-$releasever&type=free&release=1.7
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/mirrorlist.php?dist=rhel-$releasever&type=free&release=1.7
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=0
[jpackage-generic-nonfree]
name=JPackage (non-free), generic
mirrorlist=http://www.jpackage.org/jpackage_generic_nonfree_1.7.txt
failovermethod=priority
gpgcheck=1
gpgkey=http://www.jpackage.org/jpackage.asc
enabled=1
- Become root
- Copy this file to /etc/yum.repos.d. Edit it, and make sure that enabled=1 is set for the [jpackage-generic-nonfree] section.
- Make directories required by the RPM process (I suspect you can do this outside the /usr/src directory, though):
mkdir -p /usr/src/redhat/SOURCES
mkdir -p /usr/src/redhat/RPMS/i586/
- Copy the Java installation file you previously downloaded to /usr/src/redhat/SOURCES and make it executable ( chmod +x
) - Install the tools you need to build an rpm: yum install yum-utils jpackage-utils rpm-build(At the moment this seems to fail on 64bit machines because of missing dependencies)
- cd usr/src/redhat/SOURCES
- yumdownloader —source java-1.6.0-sun
- At the moment, that will download a file called java-1.6.0-sun-1.6.0.10-1jpp.nosrc.rpm
- Run setarch i586 rpmbuild —rebuild java-1.6.0-sun*nosrc.rpm. At the moment that gives an error message, which seems to be able to be ignored:
sh: /usr/src/redhat/SOURCES/jdk-6u10-linux-i586.bin: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.6041 (%prep)
RPM build errors:
user jasonc does not exist - using root
group jasonc does not exist - using root
user jasonc does not exist - using root
group jasonc does not exist - using root
user jasonc does not exist - using root
group jasonc does not exist - using root
Bad exit status from /var/tmp/rpm-tmp.6041 (%prep)
-
That previous command extracted a RPM SPEC file in the /usr/src/redhat/SPECS/ directory.
-
Edit /usr/src/redhat/SPECS/java-1.6.0-sun.spec. Find the part that says %define buildver and change the value to the build for the new version of Java
-
Run rpmbuild -ba /usr/src/redhat/SPECS/java-1.6.0-sun.spec. This extracts the JDK installer you previously downloaded and builds a set of RPMs from it.
-
cd /usr/src/redhat/RPMS/i586; ls;
java-1.6.0-sun-1.6.0.11-1jpp.i586.rpm java-1.6.0-sun-fonts-1.6.0.11-1jpp.i586.rpm
java-1.6.0-sun-alsa-1.6.0.11-1jpp.i586.rpm java-1.6.0-sun-jdbc-1.6.0.11-1jpp.i586.rpm
java-1.6.0-sun-demo-1.6.0.11-1jpp.i586.rpm java-1.6.0-sun-plugin-1.6.0.11-1jpp.i586.rpm
java-1.6.0-sun-devel-1.6.0.11-1jpp.i586.rpm java-1.6.0-sun-src-1.6.0.11-1jpp.i586.rpm
- You can now install the RPM: rpm -i java-1.6.0-sun-1.6.0.11-1jpp.i586.rpm
- For me that failed with a missing X dependency: libXtst.so.6 is needed by java-1.6.0-sun-1.6.0.11-1jpp.i586
- I fixed that with yum -y install libX11-devel libXtst.
- Use the alternatives command to set the correct version of Java: alternatives —config java
- Finally: java -version:
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
That’s it - you finally have Java working on Linux! You also have a RPM which can be installed on other machines.