Installing Sun Java JDK in CentOS 5.2

Download the Sun Java JDK from the Java SE Downloads page.

Using your root account, or the <code>sudo</code> command, run the <code>jdk-6u11-linux-i586-rpm.bin</code> (<code>chmod</code> it if necessary). This will install Java packages.

Type <code>java -version</code>. In my case, it show <code>gcj</code> info instead of Sun one.
For selecting the java command, we can use the <code>alternatives</code> program. Use:
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/latest/bin/java 2
Now run
/usr/sbin/alternatives –config java
and select option 2.

Running <code>java -version</code> now should show Sun JVM info.

Remember that maybe you want to do the same with <code>javac</code> and other Java commands.

Install Sun/Oracle Java JDK/JRE 6 on Fedora 13/14, CentOS/RHEL 5.5/6

This guide is updated/rewritten Jul 29, 2010 to use currently latest Sun/Oracle Java JDK and JRE 6 Update 21 and I added also separated 32-bit and 64-bit installation instructions.

By default, Fedora 14, Fedora 13, Fedora 12, CentOS 5.5 and Red Hat (RHEL) 5.5/6 Linux operating systems use the OpenJDK Java, which is a good choice for normal use and it works with almost all the Java programs normally. OpenJDK is also easy to install and maintain with YUM package management, but some cases, Sun/Oracle Java installation is necessary, for example, if some program have to compile with Sun/Oracle Java or a particular program does not work without Sun/Oracle Java.

Install Sun/Oracle Java JDK (Java Development Kit)/JRE (Java Runtime Environment) 6u21 on Fedora 14, Fedora 13, Fedora 12, CentOS 5.5, Red Hat (RHEL) 5.5 and Red Hat (RHEL) 6

1. Download Sun/Oracle Java JDK or JRE RPMs

Download Sun/Oracle Java JDK or JRE from here (current version is JDK 6 Update 21)
Note: Select rpm.bin package (example jdk-6u21-linux-i586-rpm.bin, jre-6u21-linux-i586-rpm.bin, jdk-6u21-linux-x64-rpm.bin or jre-6u21-linux-x64-rpm.bin).

2. Change to root user.

sudo -i ## OR ## su -

3a. Run Sun/Oracle Java JDK binary

chmod +x /path/to/file/jdk-6u21-linux-*-rpm.bin /path/to/binary/jdk-6u21-linux-*-rpm.bin   ## OR ##   sh /path/to/binary/jdk-6u21-linux-*-rpm.bin

Note: Use full file name (without asterix) if you have both i586 and x64 versions downloaded.

3b. Run Sun/Oracle Java JRE binary

chmod +x /path/to/file/jre-6u21-linux-*-rpm.bin /path/to/binary/jre-6u21-linux-*-rpm.bin   ## OR ##   sh /path/to/binary/jre-6u21-linux-*-rpm.bin

Note: Use full file name (without asterix) if you have both i586 and x64 versions downloaded.

4. Install Sun/Oracle java, Sun/Oracle javaws, Sun/Oracle (for Firefox/Mozilla) and Sun/Oracle javac with alternatives –install command

alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_21/jre/bin/java 20000 alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.6.0_21/jre/bin/javaws 20000   ## Java Browser (Mozilla) Plugin 32-bit ## alternatives --install /usr/lib/mozilla/plugins/ /usr/java/jdk1.6.0_21/jre/lib/i386/ 20000   ## Java Browser (Mozilla) Plugin 64-bit ## alternatives --install /usr/lib/mozilla/plugins/ /usr/java/jdk1.6.0_21/jre/lib/amd64/ 20000   ## Install javac only if you installed JDK (Java Development Kit) package ## alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_21/bin/javac 20000

5. Check current java, javac, javaws and versions

java -version java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b06) Java HotSpot(TM) Server VM (build 17.0-b16, mixed mode)   javac -version javac 1.6.0_21   javaws Java(TM) Web Start 1.6.0_21 [...]

Note: Check with restarting Mozilla Firefox and writing about:plugins on address bar.

6. Swap between OpenJDK and Sun/Oracle JDK versions

alternatives --config java   # or javac or javaws or There are 4 programs which provide 'java'.     Selection    Command -----------------------------------------------    1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java    2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java *  3           /usr/java/jdk1.6.0_18/jre/bin/java  + 4           /usr/java/jdk1.6.0_21/jre/bin/java   Enter to keep the current selection[+], or type selection number:

Note: java with [+] is currently on use

Post-Installation Setup

Add JAVA_HOME environment variable to /etc/profile file or $HOME/.bash_profile file

## export JAVA_HOME export JAVA_HOME="/usr/java/jdk1.6.0_21"