Skip to content

(update-)alternatives install java

Here’s the command to install an alternative installation of Java:

alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_04/bin/java 99

In this case I used the self extracting file (not the RPM) from Sun, and moved the directory to /usr/lib/jvm/jdk1.6.0_04.

To finish it off, you need to do this:

alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
   2           /usr/lib/jvm/jdk1.6.0_04/bin/java

Enter to keep the current selection[+], or type selection number: 2
[root@localhost jvm]# java -version
java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

Sometimes SELinux will prevent something from launching (e.g. Eclipse), and you’ll have to run a command like:

chcon -t textrel_shlib_t /usr/lib/jvm/jdk1.6.0_04/jre/lib/i386/

Posted in CentOS, Linux, Tips and Tricks.

6 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Dave says

    Thanks! This tip made short work of my 1st attempt at getting update-alternatives working.

  2. Abdulelah Dandachi says

    THANK YOU! I spent ages trying to find a simple-to-follow method to set an alternative JRE. Wish I’d come across this post earlier. Many thanks!

  3. suliman says

    I hate linux. It is made for fuckwits by fuckwits

  4. jtanium says

    Oh yeah, because Windows is soooooo much better…

  5. al biheiri says

    chcon -t is temporary untill next reboot.
    you will want to use
    semanage fcontext -a -t textrel_shlib_t “/usr/lib/jvm/jdk1.6.0_04/jre/lib/i386/”

  6. Abdulwajid Khan says

    Many Thanks

Some HTML is OK

or, reply to this post via trackback.