Wednesday, April 21, 2010

Add a Java runtime to Ubuntu using update-alternatives

I just installed a Java JDK not using the package system. I wanted all users in this machine to be "aware" of this java runtime so the "java" command defaults to this implementation.

Ubuntu offers the "update-alternatives" utility to do this. This is both used to configure which of your (in this case) java implementations to use, but it can also be used to add a new one to the list. Here is the recipe (run as root, or sudo all commands):
# update-alternatives --install /usr/bin/java java \
  /opt/jdk1.6.0_14_x64/bin/java 100
# update-alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /opt/jdk1.6.0_14_x64/bin/java

Enter to keep the current selection[+], or type selection number: 1
# java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
Note that in my case, since this was the only Java installed, there was no need to configure it via --config. I just ran it to make sure this one was the current choice. Also, if you do not want the interactive prompt you can just run:
sudo update-alternatives --set java /opt/jdk1.6.0_14_x64/bin/java

1 comment:

  1. I just installed a Java JDK not using the package system, anyways nice post keep up the good work

    ReplyDelete