Using GNU/Linux Alternatives – Java, Javaws and Java Plugin example

In this post I’ll briefly show an use case of Alternatives command available in Fedora, Ubuntu, Debian, and other GNU/Linux flavours.

alternatives – maintain symbolic links determining default commands

An alternative takes the following form:

[Symbolic link]  [Alt. ID]  [Real Binary]
/usr/bin/java    java       /usr/java/jdk1.7.0_55/jre/bin/java

In this example we see that a symbolic link /usr/bin/java will be created. It will point to /var/lib/alternatives/java, and this last will point to the real binary.

So it goes this way:
[Symbolic link] –> /var/lib/alternatives/[Alt. ID] –> [Real Binary]

When you change an Alternative, you change the last pointer: /etc/alternatives/[Alt. ID]–>[Real Binary]

Let’s list the alternatives and their current values. In this example we are interested in java, javaws and, three Alternative Identifiers
that I’ve created manually.

[root@i5-moll ~]$ update-alternatives --list
xinputrc    auto    /etc/X11/xinit/xinput.d/ibus.conf
cifs-idmap-plugin    auto    /usr/lib64/cifs-utils/
ld    auto    /usr/bin/ld.bfd
mkisofs    auto    /usr/bin/genisoimage
javaws    manual    /usr/java/jre1.8.0_05/bin/javaws    manual    /usr/java/jre1.8.0_05/lib/amd64/
unrar    auto    /usr/bin/unrar-nonfree
jre_openjdk    manual    /usr/lib/jvm/java-1.7.0-openjdk-
jre_1.7.0_openjdk    auto    /usr/lib/jvm/jre-1.7.0-openjdk-
google-chrome    auto    /usr/bin/google-chrome-stable
mta    manual    /usr/sbin/sendmail.sendmail
java    manual    /usr/lib/jvm/jre-1.7.0-openjdk/bin/java

Let’s remove the Java configuration. We can do it by command or by hand. We show here by-hand, read the “–remove” flag otherwise.

[root@i5-moll ~]# rm /var/lib/alternatives/java

Now list the configuration of java, it’ll be empty:
[lipi@i5-moll ~]$ update-alternatives --config java
[lipi@i5-moll ~]$

Now create a new Alternative. In my case I have 3 JRE installed on my system, JRE 1.8, JDK 1.7, and OpenJDK 1.7:
[root@i5-moll ~]# alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_40/bin/java 200000
[root@i5-moll ~]# alternatives --install /usr/bin/java java /usr/java/jre1.8.0_05/bin/java 200000
[root@i5-moll ~]# alternatives --install /usr/bin/java java /usr/lib/jvm/jre-1.7.0-openjdk/bin/java 200000

Now select your preferred version and test that the switch takes effect:
[root@i5-moll ~]# update-alternatives --config java
Hi ha 3 programes que proveeixen 'java'.
Selecció     Ordre
* 1           /usr/java/jdk1.7.0_40/bin/java
+ 2           /usr/java/jre1.8.0_05/bin/java
3           /usr/lib/jvm/jre-1.7.0-openjdk/bin/java
Premeu la tecla de retorn per mantenir la selecció actual[+], o teclegeu el número de la selecció: 2
[root@i5-moll ~]# java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Do the same for the Java Browser Plugin. Create a new alternative or update the existing one. I created one called
The path for my browser plugins directory is /usr/lib64/mozilla/plugins/ (Firefox 28.0).

[root@i5-moll ~]# alternatives --install /usr/lib64/mozilla/plugins/ /usr/lib64/ 200000
[root@i5-moll ~]# alternatives --install /usr/lib64/mozilla/plugins/ /usr/java/jre1.8.0_05/lib/amd64/ 200000
[root@i5-moll ~]# alternatives --install /usr/lib64/mozilla/plugins/ /usr/java/jre1.8.0_05/lib/amd64/ 200000

Use the following to choose the alternative:
[root@i5-moll ~]# update-alternatives --config

Check that it worked opening your browser and surfing to “about:plugins”.

And finally, do the same for Java Web Starter.

[root@i5-moll ~]# alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.7.0_40/bin/javaws 200000
[root@i5-moll ~]# alternatives --install /usr/bin/javaws javaws /usr/java/jre1.8.0_05/bin/javaws 200000
[root@i5-moll ~]# alternatives --install /usr/bin/javaws javaws /usr/bin/javaws.itweb 200000

Use the following to choose the alternative:
[root@i5-moll ~]# update-alternatives --config javaws

Check that it worked executing javaws.