Install Java 6 Update 10 on Ubuntu 8.04
I had to install Java 6 Update 10 on Ubuntu 8.04. The thing is straight forward if you do not want to integrate the new JVM into Ubuntus alternatives system (and do not need teh new Java Plugin in your browser). Download, install, modify your PATH, JAVA_HOME and JDK_HOME, done. Google helped to find this really good description of the process, including moving the JVM to /usr/lib/jvm, where Ubuntu expects the JVMs.
The tricky part is the integration into Ubuntus alternatives system. It provides an easy way to switch between VMs and is usable even by “non geek” users and update-java-alternatives will also switch your java browser plugin.
We have to have Java 6 installed from the Ubuntu repositories:
sudo apt-get install sun-java6-jdk
Now, follow Caspers first two steps to install the VM. Download Update 10 and execute the script
sh jdk-6u10-rc2-bin-b32-linux-amd64-12_sep_2008.bin
Move the directory to /usr/lib/jvm, where Ubuntu expects JVMs
sudo mv jdk1.6.0_10 java-6-sun-1.6.0.10
sudo mv jdk1.6.0_10/ /usr/lib/jvm
And create a symlink
cd /usr/lib/jvm
sudo ln -s java-6-sun-1.6.0.10 java-6.10-sun
The directory should look more or less like this
lrwxrwxrwx 1 root root 23 2008-10-07 19:01 java-1.5.0-sun -> java-1.5.0-sun-1.5.0.15
drwxr-xr-x 10 root root 4096 2008-10-08 11:34 java-1.5.0-sun-1.5.0.15
-rw-r--r-- 1 root root 2165 2008-03-26 02:28 .java-1.5.0-sun.jinfo
lrwxrwxrwx 1 root root 19 2008-10-08 12:21 java-6.10-sun -> java-6-sun-1.6.0.10
lrwxrwxrwx 1 root root 19 2008-10-07 19:00 java-6-sun -> java-6-sun-1.6.0.06
drwxr-xr-x 8 root root 4096 2008-10-08 11:35 java-6-sun-1.6.0.06
drwxr-xr-x 10 root root 4096 2008-10-08 11:40 java-6-sun-1.6.0.10
-rw-r--r-- 1 root root 2341 2008-10-08 11:47 .java-6-sun.jinfo
To integrate the new VM into the alternatives system, we use update-alternatives --install to get new alternatives and provide a .jinfo file used by update-java-alternatives. For simplicity, I (and the script) assume that you have Java 6 installed. We need the Java 6 .jinfo file as a template. Basically, we h clone and modify the file, such that all the links point to the appropriate directory. Well, that can be done with your favourite text editor. The ugly part is, you have to call udpate-alternatives --install for ALL the commands. That calls for a script
.
#!/usr/bin/perl
use strict;
# use this as template - we assume that you have java 6 installed
# its in the repo !
my $jvm_template="java-6-sun";
my $jvm_template_path="/usr/lib/jvm/java-6-sun";
# this is the new jvm
my $jvm_name="java-6-sun-1.6.0.10";
my $jvm_alias="java-6.10-sun";
my $jvm_path="/usr/lib/jvm/java-6.10-sun";
my $jvm_priority=64;
my $jvm_section="non-free";
open(JINFO_OUT, ">/usr/lib/jvm/.$jvm_alias.jinfo") or die "Can not write jinfo file !";
#write header
print JINFO_OUT "name=$jvm_name\n";
print JINFO_OUT "alias=$jvm_alias\n";
print JINFO_OUT "priority=$jvm_priority\n";
print JINFO_OUT "section=$jvm_section\n\n";
my @lines = ();
open(IN, "/usr/lib/jvm/.$jvm_template.jinfo") or die "Can note read jinfo template!";
@lines = <IN>;
close(IN);
my @new_config = ();
foreach(@lines){
if($_=~ /$jvm_template_path/){
chomp($_);
$_ =~ s/$jvm_template_path/$jvm_path/;
push(@new_config, $_);
print JINFO_OUT "$_\n";
}
}
close(JINFO_OUT);
foreach(@new_config){
my @split = split(' ', $_);
system("update-alternatives --install /usr/bin/@split[1] @split[1] @split[2] $jvm_priority");
}
Download the script and execute it (with sudo/as root – we have to write to /usr/lib/jvm) after you have moved the update 10 installation to /usr/lib/jvm/java-6-sun-1.6.0.10 and created the symlink to java-6.10-sun as described above. (The script is quick and dirty. The names are defined in the first lines. If you have used other directory/alias names, you have to modify the script).
sudo perl create-jvm-alternative-6.10.pl
This generates a .jinfo file in /usr/lib/jvm and it calls update-alternatives --install for all the things mentioned in the template .jinfo. The update-alternatives takes a generic name as first argument (thanks Jonathan – I should read man pages more often). This is created as a symlink pointing to the actual name in /etc/alternatives. /etc/alternatives then points to the currently chosen alternative. SO, for example, at some point the script calls:
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6.10/bin/java
This creates two symlinks
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-6.10/bin/java
The latter might already exist and point to some java alternative (i.e. java v1.5). As far as I’ve seen this is not overwritten. The latter symlink is the one that is actually changed when you switch alternatives.
When everything is done, you should get something like:
thasso@antef:~> update-java-alternatives -l
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-6.10-sun 64 /usr/lib/jvm/java-6.10-sun
java-6-sun 63 /usr/lib/jvm/java-6-sun
I recently tried the method described in the linking article ( http://coffeecokeandcode.blogspot.com/2008/09/installing-java-6-update-10-on-ubuntu.html ) in Kubuntu 8.04 but had no success. This is curious because I was recently able to successfully get Java 6u10 RC2 running as the system wide default on another, bit ever so slightly older system. ( in terms of updates )
I saw the link to your article and decided to try your method. Unfortunately, the first problem I encountered was a compilation error in the Perl script : ‘Global symbol “$result” requires explicit package name at create-jvm-alternative-6.10.pl line 42. Execution of create-jvm-alternative-6.10.pl aborted due to compilation errors.’ . This was easily corrected by giving “$result” the null/main package name “::” : “$::result” . After that correction, the script ran successfully and executing “update-java-alternatives –list” contained “java-6.10-sun 64 /usr/lib/jvm/java-6.10-sun” in the output, so I thought I was set : Not so.
Attempting to execute the “java” from the command line produces the error :
“The program ‘java’ can be found in the following packages:
* java-gcj-compat-headless
* openjdk-6-jre-headless
* cacao
* j2re1.4
* kaffe
* jamvm
* gij-4.1
* gij-4.2
* sablevm
Try: sudo apt-get install
bash: java: command not found”
So, I checked for the presence of Java in /usr/bin but it was nowhere to be found! The only references to it I could find were via the whereis command which produced the following output :
“java: /etc/java /usr/lib/java /usr/share/java”
I would be greatly appreciative if you could offer some advice on how to resolve this problem.
Thanks,
Jonathan
As a partial answer to my own question, I think that the “stupid” symbolic links created by update-alternatives might be part of the answer. For example, the java link generated points to /etc/alternatives/java which in turn points to /usr/lib/jvm/java-6.10-sun/jre/bin/java . One obvious path to follow would be to copy the java link to /usr/bin , which I’ve done. But doing just that results in the following error upon the execution of Java :
“java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory”
This is strange since libjli.so definitely exists in /usr/lib/jvm/java-6.10-sun/jre/lib/i386/jli . One apparent quick fix is to add/update the JDK_HOME and JAVA_HOME environment variables in ~/.bashrc to point to /usr/lib/jvm/java-6.10-sun. Unfortunately, that doesn’t seem to work, as well as being an ugly kludge.
It seems to me that the symbolic links created by the alternatives system need to be put in the right place. ( /usr/bin ? ) If not, perhaps there is another more complete and elegant solution to this problem.
As for me, I’m not just going to copy all the links over to /usr/bin just yet, since I don’t even know if that is the correct or even a valid course of action ( arrrrr, I don’t know what I’m doin’
which means for the time being I’m stuck with Java in a broken state.
Jonathan
Jonathan,
you were right, the stupid links were not so stupid after all
I updated the script and the text. As far as I got it know, what I did wrong was the interpretation of the “generic name” (man update-alternatives). I simply used java, but the man page states:
“A name, like /usr/bin/editor, which refers, via the alternatives system, to one of a number of files of similar function.”
I switched to full path generic names, so /usr/bin/java instead of just java. This seems to do the right thing and the links get created appropriately in /usr/bin.
Execute the updated script. It should fix your problem. At least it will “recreate” the links in /usr/bin (I still do not understand why they disappeared – the script does not delete anything and the man page does not say anything about removing existing links ).
Let me know if it helped.
cheers
Works perfectly! Other than having to manually install the Java plugin and Java Web Start ( which the Sun install docs say you have to do anyway — at least for Linux ) I did not have to do anything else.
Also, I’ve verified that your solution does indeed fully comply with the Alternatives system as I was able to switch between JVM’s using ‘update-java-alternatives –set’
Thanks a lot for your help and work! It is greatly appreciated.
Jonathan
Regarding manually installing the Java plugin and Web Start in the above message, it occurred to me that one other improvement could be made to the Perl script. Specifically, the new java-6.10-sun alternative needs to have at least 1 *slave* link associated with it that points to the correct man page. It would be even better if the generic Java plugin link — libjavaplugin_oji.so — in usr/lib/firefox as well as the links needed for Java Web Start were also integrated into the alternatives system as slave links to the java-6.10-sun alternative. That way, when one chooses to change JVMs via eg. ‘update-java-alternatives –set’ the browser plugin and man pages are changed as well, in accordance with the chosen JVM.
Just a suggestion.
Jonathan
Yes, you are right. Switching the java plugin instantly (or least with a firefox restart) would be really nice. When I find the time, I will try to integrate that and the fixing the links to the man pages.
cheers
Good post.
How did you manually Java plugin and Web Start on Firefox 3?
Thanks
I meant “manually install”
Sorry,
Raimon,
I am not eaxtly sure and I don’t have a Ubuntu system at hand right now, but as far as I remember:
For the plugin, you have to remove the old and ass sysmlinks to the new plugin in /usr/lib/firefox. See
http://java.sun.com/javase/6/webnotes/install/jre/manual-plugin-install-linux.html
for detailed instructions from sun. I think they assume that you have the stuff installed in your home directory, but I think you can easily adopt that to /usr/lib/firefox.
I am not sure about JavaWebstart. I would change anything except for the file association with .jnlp. Just tell your browser to start with the javaws binary from the java version you want to use. This should be enough to get things started with the right webstart version.
sorry, but I can not give you any more details right now, because I currently do not have access to a Ubuntu machine.
cheers,
Thasso