Saturday, October 29, 2011

Working Java 7 on Ubuntu Oneiric Ocelot 11.10 (update-alternatives)

I still have not figured out why the default openjdk installation on Ubuntu 11.10 seems broken. With broken I mean that there are no entries in the alternatives database and no command in the path (which follows from not being the default alternative).

As a consequence, I did the same old mumbo jumbo with update-alternatives. As the openjdk-7 is in /usr/lib/jvm/java-7-openjdk-i386/, I just run the following commands:

% sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-openjdk-i386/bin/java 4 
% sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-openjdk-i386/bin/javac 4     t
% sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-openjdk-i386/bin/jar 4 

I guess I may want to do  the trick for more executable stuff. Moreover, I have no idea whether the browser plugin works or not. It has been ages since I actually used it and right at the moment I do not care. Hope this will be helpful.

After that, just call the appropriate update-alternatives --config ja(vac|va|r) stuff!

I almost forgot... I just installed the plain openjdk-7-jdk/jdr stuff from the official ubuntu repositories.

Besides... I have seen a package sun-java-{yadda-yadda}-bin which may have been the provider of the links in the first place (when I was using sun's JDK which was correctly packaged). Right at the moment I cannot see a similar package for OpenJDK. My Ubuntu went postal recently and consequently I cannot verify. :(

4 comments:

Lazza said...

Thank you very much for the post. I was trying to figure out what was wrong with my javac!

Grazie ancora. ;)

Unknown said...

I think it has something to do also with a package named sun-*-bin which I believe contained the instructions to create the symlink and there is not such package for openjdk.

This is speculation, though. Right now my Ubuntu is broken and does not boot outside repair more. No time to fix it.

samb said...

Thanks very much mate. For those n00b like me, once you've updated the alternatives db, you need to run
sudo update-alternatives --config java and select your newly created jdk7 entry so that the /etc/alternatives/java symlink is updated. Repeat for javac and jar

Unknown said...

You're welcome! And yeah, perhaps I should have mentioned that after that update-alternatives --config is needed.