Posts Tagged Red Hat

update-alternatives on CentOS

centOS 6

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 -version
java 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 java
There 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 -version
java 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

, ,

5 Comments