
These days I had to update the java version on a server at work. They had jre-1.6.0-openjdk version wanted to use Oracle’s jdk1.6.0_33 version. What it seems odd to me was to find out update-alternatives on CenOS, because I knew it from Debian based distributions. Reading the documentation on CentOS, it is a reimplementation of Debian’s update-alternatives, but aimed to Red Hat based distributions, thus for CentOS as well. So, let’s see how to update Java with update-alternatives on CentOS as example.
Using update-alternatives for Java
The first thing to do is to check the current java version:
# java -versionjava version "1.6.0_17" OpenJDK Runtime Environment (IcedTea6 1.7.4) (rhel-1.21.b17.el6-x86_64) OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
Here you can see it points to OpenJDK’s 1.6.0_17 version. Now let’s add a path to the version to use:
# update-alternatives --install /usr/bin/java java /opt/jdk1.6.0_33/bin/java 1
Last line adds the /opt/jdk1.6.0_33/bin/java path to /usr/bin/java java binary, in other words, it creates a symbolic link to use in case that options is chosen. Let’s set an alternative that points to the new path:
# update-alternatives --config javaThere are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java 2 /opt/jdk1.6.0_33/bin/java Enter to keep the current selection[+], or type selection number: 2
Let’s check the java version one more time:
# java -versionjava version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)
Now the binary points to the Oracle’s version. You can check it with the symbolic links:
# ls -l /usr/bin/java lrwxrwxrwx. 1 root root 22 Jul 31 15:25 /usr/bin/java -> /etc/alternatives/java# ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 25 Jul 31 15:25 /etc/alternatives/java -> /opt/jdk1.6.0_33/bin/java
Planeta Linux
#1 by Luis Gallardo on 30/10/2012 - 3:09 pm
@Rodrigo lee los comentarios de ese mismo artículo. En particular el #14. Saludos!
#2 by Rodrigo on 30/10/2012 - 2:12 pm
buenas luis mira no puedo comentar en el post del q quiero una solucion asi q te escribo en este mi problema es q le puse este frimware http://lgallardo.com/2011/05/22/instalacion-de-openwrt-en-tp-link-tl-wr1043nd/comment-page-2/#comments
andaba de 10 pero cuando quise volver a la version original del router murio se colgo y lo unico q hace el router es prender y apagar las luces quisiera saber q hago tienes alguna solucion algun programa p revivir router noce necesito algo gracias
#3 by Luis Gallardo on 03/08/2012 - 2:49 pm
@Mark you are welcome. Great to hear it works for you as well. Cheers!
#4 by Mark on 03/08/2012 - 1:41 pm
Luis. Thank you very much for posting this. Just ran it and changed OpenJDK to sun’s Java 7u5. Worked as advertised. All the other posts I found had way too many steps listed.