Using Sun Java instead of OpenJDK
How to download, install, and switch to Sun's Java. Covers the JRE (browser plugin, java runtime, utils), and the JDK (JRE + dev tools); 32-bit and 64-bit.
Applicable to Fedora Versions
- Fedora 12+
Doing the Work
If, for whatever reason, OpenJDK isn't working 100% for you, then here's how to use Sun Java instead:
-
Download the latest update of the Sun Java JRE or JDK by clicking the "Download JRE" button (for users) or the "Download JDK" button (for developers) from the "Java Platform, Standard Edition" section located here:
http://www.oracle.com/technetwork/java/javase/downloads/index.htmlAccept the license agreement and download either the "Linux x86 - RPM Installer" if running 32-bit Fedora, or the "Linux x64 - RPM Installer" if 64-bit.
IMPORTANT: When downloading Java 7, download the .rpm version, and not the ".tar.gz" version (unless you know what you're doing). If downloading the older Java 6 release, make sure to get the "*-rpm.bin" (RPM) option; NOT the self-extracting installer version with only ".bin" in the filename. e.g.:
- Java 7 downloads
- JRE 7 (for users who only require the plugin, and the java runtime):
- jre-7-linux-i586.rpm (32-bit)
- jre-7-linux-x64.rpm (64-bit)
- JDK 7 (for developers):
- jdk-7-linux-i586.rpm (32-bit)
- jdk-7-linux-x64.rpm (64-bit)
- Java 6 downloads
- JRE 6 (for users who only require the plugin, and the java runtime):
- jre-6u25-linux-i586-rpm.bin (32-bit)
- jre-6u25-linux-x64-rpm.bin (64-bit)
- JDK 6 (for developers):
- jdk-6u25-linux-i586-rpm.bin (32-bit)
- jdk-6u25-linux-x64-rpm.bin (64-bit)
- Install it:
If Java 7:su -c 'yum install jdk-7-linux-x64.rpm'
If installing the older Java 6:su -c 'sh jdk-6u25-linux-x64-rpm.bin'
Press ENTER when prompted. Firefox will open (as root) if running X; close it immediately. - Configure Fedora to use the Sun Java browser plugin instead of OpenJDK's
- If JRE (32-bit):
su -c 'alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/default/lib/i386/libnpjp2.so 20000'
- If JRE (64-bit):
su -c 'alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/default/lib/amd64/libnpjp2.so 20000'
- If JDK (32-bit):
su -c 'alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/default/jre/lib/i386/libnpjp2.so 20000'
- If JDK (64-bit):
su -c 'alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/default/jre/lib/amd64/libnpjp2.so 20000'
Test the plugin out at: www.java.com/en/download/help/testvm.xml
A browser restart is not always required.
- If JRE (32-bit):
-
Configure Fedora to use the Sun 'java' runtime (JRE-only) and all the other java utils (JDK)
- METHOD #1: Using a PATH override
Run the following as root to create the sunjava.sh path override file
cat <<EOF>> /etc/profile.d/sunjava.sh
export JAVA_HOME=/usr/java/default
export PATH=\$JAVA_HOME/bin:\$PATH
EOFLogout then log back in for the new $PATH environment to take effect globally (or run "source /etc/profile.d/sunjava.sh" to set the PATH for the current session)
NOTE: To switch back to using OpenJDK when using this PATH override, you either need to uninstall sun java (yum remove jdk sun-javadb\*), or remove or comment out the PATH override set in sunjava.sh
- METHOD #2: Using /etc/alternatives
This is the more "correct" way to switch between *ALL* of Sun Java and OpenJDK, but it's quite a bit more unwieldy. Hopefully at some point Sun will set the alternatives up themselves when their rpm packages are installed: TODO: rewrite the paths below using /usr/java/default/{jre/}* as a base depending on JRE/JDK; not sure how to handle the other alternatives in /usr/lib reference: rpm -q --scripts java-1.6.0-openjdk # JRE rpm -q --scripts java-1.6.0-openjdk-devel # JDK
- METHOD #1: Using a PATH override
Troubleshooting
How to test
Test the plugin out at: www.java.com/en/download/help/testvm.xmlCommon problems and fixes
More Information
Disclaimer
We test this stuff on our own machines - really we do - but you may run into problems; if you do, come to #fedora on irc.freenode.net

