Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have Ubuntu 12.04 amd64 installed on my machine, on the previous versions of Ubuntu it was deadly easy, now there is this command update-java-alternatives with a really bad man page.

I just have my JDK unpacked on a mounted partition like /media/mydisk/jdk, how i can force the use of that JDK instead of the one that comes in the Ubuntu repository?

What is the logic behind this update-java-alternatives ?

share|improve this question

6 Answers 6

up vote 11 down vote accepted

Note: update-java-alternatives won't work with manual installations. In any case, it doesn't look like it has any special abilities which update-alternatives doesn't have, except convenience.

As a graphical alternative to @AnwarShah's command-line method, consider using Gnome Alternatives (sudo apt-get install galternatives):

  • Start GAlternatives, select each java option, change it to manual, and Add your alternative (the example here is the IBM JRE installed in my home directory):

    enter image description here

    enter image description here

    enter image description here

share|improve this answer
    
I am noticing the same thing: that the update-java-alternatives command does not work with a manually installed Oracle JDK, such as '/opt/java/jdk1.7.0_25'. Very annoying. –  djangofan Jun 26 '13 at 22:12

I actually use these commands to install jdk1.6.0_25.

sudo update-alternatives --install /usr/bin/java java /media/mydisk/jdk/bin/java 100
sudo update-alternatives --install /usr/bin/javac javac /media/mydisk/jdk/javac 100
sudo update-alternatives --install /usr/bin/java_vm java_vm /media/mydisk/jdk/bin/java_vm 100
sudo update-alternatives --install /usr/bin/jcontrol jcontrol /media/mydisk/jdk/bin/jcontrol 100
sudo update-alternatives --install /usr/bin/jexec jexec /media/mydisk/jdk/jre/lib/jexec 100
sudo update-alternatives --install /usr/bin/jexec jexec /media/mydisk/jdk/jre/lib/jexec 100 --slave /usr/share/binfmts/jar jexec-binfmt media/mydisk/jdk/jre/lib/javaws

And then you can use these command to set as default. Most probably, these aren't needed.

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config java_vm
sudo update-alternatives --config jcontrol
sudo update-alternatives --config jexec

You can get more help by using the command man update-alternatives or you can see the manual in your browser here

The purpose of the update-java-alternatives as described in the manual page is

update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language. A package does provide these information of it's alternatives in /usr/lib/jvm/.<jname>.jinfo.

All the jdk tools are

appletviewer extcheck idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc

Hope this will help you.

share|improve this answer

You can do this with sudo update-alternatives :

# Adding a new alternative for "java"
sudo update-alternatives --install /usr/bin/java java /media/mydisk/jdk/bin java 1

# Setting the new alternative as default for "java"
sudo update-alternatives --config java

You have to do this for other jdk components too. These components are appletviewer, extcheck, idlj, jar, jarsigner, javac, javadoc, javah, javap, javaws, jconsole, jdb, jexec, jhat, jinfo, jmap, jps, jrunscript, jsadebugd, jstack, jstat, keytool, mozilla-javaplugin.so, native2ascii, policytool, rmic, rmid, rmiregistry, schemagen, serialver, servertool, tnameserv, unpack200, wsgen, wsimport, xjc.

For further informations, you can see the man pages for update-alternatives : man update-alternatives.

update-java-alternatives sets alternatives for java components and it seems to use update-alternatives for this.

share|improve this answer

To set up a complete jdk alternative one can use the below command:

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_45/bin/java 2 --slave /usr/bin/appletviewer appletviewer  /usr/lib/jvm/jdk1.7.0_45/bin/appletviewer --slave /usr/bin/java-rmi.cgi java-rmi.cgi  /usr/lib/jvm/jdk1.7.0_45/bin/java-rmi.cgi --slave /usr/bin/jmap jmap  /usr/lib/jvm/jdk1.7.0_45/bin/jmap --slave /usr/bin/jstatd jstatd  /usr/lib/jvm/jdk1.7.0_45/bin/jstatd --slave /usr/bin/policytool policytool  /usr/lib/jvm/jdk1.7.0_45/bin/policytool --slave /usr/bin/servertool servertool  /usr/lib/jvm/jdk1.7.0_45/bin/servertool --slave /usr/bin/apt apt  /usr/lib/jvm/jdk1.7.0_45/bin/apt --slave /usr/bin/javac javac  /usr/lib/jvm/jdk1.7.0_45/bin/javac --slave /usr/bin/jcmd jcmd  /usr/lib/jvm/jdk1.7.0_45/bin/jcmd --slave /usr/bin/jps jps  /usr/lib/jvm/jdk1.7.0_45/bin/jps --slave /usr/bin/jvisualvm jvisualvm  /usr/lib/jvm/jdk1.7.0_45/bin/jvisualvm --slave /usr/bin/rmic rmic  /usr/lib/jvm/jdk1.7.0_45/bin/rmic --slave /usr/bin/tnameserv tnameserv  /usr/lib/jvm/jdk1.7.0_45/bin/tnameserv --slave /usr/bin/extcheck extcheck  /usr/lib/jvm/jdk1.7.0_45/bin/extcheck --slave /usr/bin/javadoc javadoc  /usr/lib/jvm/jdk1.7.0_45/bin/javadoc --slave /usr/bin/jconsole jconsole  /usr/lib/jvm/jdk1.7.0_45/bin/jconsole --slave /usr/bin/jrunscript jrunscript  /usr/lib/jvm/jdk1.7.0_45/bin/jrunscript --slave /usr/bin/keytool keytool  /usr/lib/jvm/jdk1.7.0_45/bin/keytool --slave /usr/bin/rmid rmid  /usr/lib/jvm/jdk1.7.0_45/bin/rmid --slave /usr/bin/unpack200 unpack200  /usr/lib/jvm/jdk1.7.0_45/bin/unpack200 --slave /usr/bin/idlj idlj  /usr/lib/jvm/jdk1.7.0_45/bin/idlj --slave /usr/bin/javafxpackager javafxpackager  /usr/lib/jvm/jdk1.7.0_45/bin/javafxpackager --slave /usr/bin/jdb jdb  /usr/lib/jvm/jdk1.7.0_45/bin/jdb --slave /usr/bin/jsadebugd jsadebugd  /usr/lib/jvm/jdk1.7.0_45/bin/jsadebugd --slave /usr/bin/native2ascii native2ascii  /usr/lib/jvm/jdk1.7.0_45/bin/native2ascii --slave /usr/bin/rmiregistry rmiregistry  /usr/lib/jvm/jdk1.7.0_45/bin/rmiregistry --slave /usr/bin/wsgen wsgen  /usr/lib/jvm/jdk1.7.0_45/bin/wsgen --slave /usr/bin/jar jar  /usr/lib/jvm/jdk1.7.0_45/bin/jar --slave /usr/bin/javah javah  /usr/lib/jvm/jdk1.7.0_45/bin/javah --slave /usr/bin/jhat jhat  /usr/lib/jvm/jdk1.7.0_45/bin/jhat --slave /usr/bin/jstack jstack  /usr/lib/jvm/jdk1.7.0_45/bin/jstack --slave /usr/bin/orbd orbd  /usr/lib/jvm/jdk1.7.0_45/bin/orbd --slave /usr/bin/schemagen schemagen  /usr/lib/jvm/jdk1.7.0_45/bin/schemagen --slave /usr/bin/wsimport wsimport  /usr/lib/jvm/jdk1.7.0_45/bin/wsimport --slave /usr/bin/jarsigner jarsigner  /usr/lib/jvm/jdk1.7.0_45/bin/jarsigner --slave /usr/bin/javap javap  /usr/lib/jvm/jdk1.7.0_45/bin/javap --slave /usr/bin/jinfo jinfo  /usr/lib/jvm/jdk1.7.0_45/bin/jinfo --slave /usr/bin/jstat jstat  /usr/lib/jvm/jdk1.7.0_45/bin/jstat --slave /usr/bin/pack200 pack200  /usr/lib/jvm/jdk1.7.0_45/bin/pack200 --slave /usr/bin/serialver serialver  /usr/lib/jvm/jdk1.7.0_45/bin/serialver --slave /usr/bin/xjc xjc  /usr/lib/jvm/jdk1.7.0_45/bin/xjc

I used this after I extracted the tar.gz file for sun jdk1.7 to /usr/lib/jvm/

You would want to replace jdk1.7.0 with the directory name of the version you have and the number 2 to whatever number you want the alternative to be.

share|improve this answer

#I've written simple script

(
lookforJdks=~
echo $lookforJdks
jdks=`test -e ./javac || find $lookforJdks -type d -iname '*jdk1.*' 2> /dev/null`
#set -e
echo 'which jdk do you want to choose? looking for jdks. This might take a while'
echo $"$jdks" | awk '{printf("%5d : %s\n", NR,$0)}'
read choose
test -e ./javac || cd `echo $"$jdks" | cut -d' ' -f $choose`/bin
for e in java javac java_vm jcontrol jexec; do sudo update-alternatives --install /usr/bin/$e $e $(readlink -f ./$e) 100; done
)
share|improve this answer

Some of java related links are at master level and cannot be used as slave in update-alternatives --install. Used the following commands to install oracle jdk and update alternatives. Hope it helps.

update-alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_45/bin/java 10000 --slave /usr/bin/appletviewer appletviewer /usr/java/jdk1.7.0_45/bin/appletviewer --slave /usr/bin/java-rmi.cgi java-rmi.cgi /usr/java/jdk1.7.0_45/bin/java-rmi.cgi --slave /usr/bin/jmap jmap /usr/java/jdk1.7.0_45/bin/jmap --slave /usr/bin/jstatd jstatd /usr/java/jdk1.7.0_45/bin/jstatd --slave /usr/bin/apt apt /usr/java/jdk1.7.0_45/bin/apt --slave /usr/bin/javac javac /usr/java/jdk1.7.0_45/bin/javac --slave /usr/bin/jcmd jcmd /usr/java/jdk1.7.0_45/bin/jcmd --slave /usr/bin/jps jps /usr/java/jdk1.7.0_45/bin/jps --slave /usr/bin/jvisualvm jvisualvm /usr/java/jdk1.7.0_45/bin/jvisualvm --slave /usr/bin/rmic rmic /usr/java/jdk1.7.0_45/bin/rmic --slave /usr/bin/extcheck extcheck /usr/java/jdk1.7.0_45/bin/extcheck --slave /usr/bin/javadoc javadoc /usr/java/jdk1.7.0_45/bin/javadoc --slave /usr/bin/jconsole jconsole /usr/java/jdk1.7.0_45/bin/jconsole --slave /usr/bin/jrunscript jrunscript /usr/java/jdk1.7.0_45/bin/jrunscript --slave /usr/bin/idlj idlj /usr/java/jdk1.7.0_45/bin/idlj --slave /usr/bin/javafxpackager javafxpackager /usr/java/jdk1.7.0_45/bin/javafxpackager --slave /usr/bin/jdb jdb /usr/java/jdk1.7.0_45/bin/jdb --slave /usr/bin/jsadebugd jsadebugd /usr/java/jdk1.7.0_45/bin/jsadebugd --slave /usr/bin/native2ascii native2ascii /usr/java/jdk1.7.0_45/bin/native2ascii --slave /usr/bin/wsgen wsgen /usr/java/jdk1.7.0_45/bin/wsgen --slave /usr/bin/jar jar /usr/java/jdk1.7.0_45/bin/jar --slave /usr/bin/javah javah /usr/java/jdk1.7.0_45/bin/javah --slave /usr/bin/jhat jhat /usr/java/jdk1.7.0_45/bin/jhat --slave /usr/bin/jstack jstack /usr/java/jdk1.7.0_45/bin/jstack --slave /usr/bin/schemagen schemagen /usr/java/jdk1.7.0_45/bin/schemagen --slave /usr/bin/wsimport wsimport /usr/java/jdk1.7.0_45/bin/wsimport --slave /usr/bin/jarsigner jarsigner /usr/java/jdk1.7.0_45/bin/jarsigner --slave /usr/bin/javap javap /usr/java/jdk1.7.0_45/bin/javap --slave /usr/bin/jinfo jinfo /usr/java/jdk1.7.0_45/bin/jinfo --slave /usr/bin/jstat jstat /usr/java/jdk1.7.0_45/bin/jstat --slave /usr/bin/serialver serialver /usr/java/jdk1.7.0_45/bin/serialver --slave /usr/bin/xjc xjc /usr/java/jdk1.7.0_45/bin/xjc

update-alternatives --install /usr/bin/policytool policytool /usr/java/jdk1.7.0_45/bin/policytool 10000 update-alternatives --install /usr/bin/servertool servertool /usr/java/jdk1.7.0_45/bin/servertool 10000 update-alternatives --install /usr/bin/tnameserv tnameserv /usr/java/jdk1.7.0_45/bin/tnameserv 10000 update-alternatives --install /usr/bin/keytool keytool /usr/java/jdk1.7.0_45/bin/keytool 10000 update-alternatives --install /usr/bin/rmid rmid /usr/java/jdk1.7.0_45/bin/rmid 10000 update-alternatives --install /usr/bin/unpack200 unpack200 /usr/java/jdk1.7.0_45/bin/unpack200 10000 update-alternatives --install /usr/bin/rmiregistry rmiregistry /usr/java/jdk1.7.0_45/bin/rmiregistry 10000 update-alternatives --install /usr/bin/orbd orbd /usr/java/jdk1.7.0_45/bin/orbd 10000 update-alternatives --install /usr/bin/pack200 pack200 /usr/java/jdk1.7.0_45/bin/pack200 10000

PS: Should be executed as root/sudo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.