December 16, 2011
They do this by manipulating a flock of symbolic links. The critical symbolic links are in the directory /etc/alternatives. As a specific example, the "java" command will (unless you have done something unusual) try to run /usr/bin/java. This is a link to /etc/alternatives/java which in turn is a link to whatever java thing ought to be run.
You could fiddle with all these links by hand, but fedora provides a utility called "alternatives" to take care of this.
If you take the path of least resistance and install OpenJDK from yum or rpm, the links will be made for you. If you install Java from Sun/oracle, their packaging is Fedora agnostic and will not make the links, so you will have to make them yourself.
Suppose you had just installed Java 7 SDK from Sun, what you would need to do is:
su ## java ## alternatives --install /usr/bin/java java /usr/java/jdk1.7.0/jre/bin/java 20000 ## javaws (32-bit only) ## alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0/jre/bin/javaws 20000 ## Java Browser (Mozilla) Plugin 32-bit ## alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jdk1.7.0/jre/lib/i386/libnpjp2.so 20000 ## Java Browser (Mozilla) Plugin 64-bit ## alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jdk1.7.0/jre/lib/amd64/libnpjp2.so 20000 ## Install javac only if you installed JDK (Java Development Kit) package ## alternatives --install /usr/bin/javac javac /usr/java/jdk1.7.0/bin/javac 20000 alternatives --install /usr/bin/jar jar /usr/java/jdk1.7.0/bin/jar 20000
For the JRE, you would do this:
su ## java ## alternatives --install /usr/bin/java java /usr/java/jre1.7.0/bin/java 20000 ## javaws (32-bit only) ## alternatives --install /usr/bin/javaws javaws /usr/java/jre1.7.0/bin/javaws 20000 ## Java Browser (Mozilla) Plugin 32-bit ## alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so /usr/java/jre1.7.0/lib/i386/libnpjp2.so 20000 ## Java Browser (Mozilla) Plugin 64-bit ## alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/jre1.7.0/lib/amd64/libnpjp2.so 20000
java -version java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode) javaws Java(TM) Web Start 1.7.0 [...] javac -version javac 1.7.0
To check what firefox is doing, restart firefox and then type about:plugins in the URL entry field.
alternatives --config java
Adventures in Computing / tom@mmto.org