30.09.2017

Ubuntu /etc/alternatives/java et.al.: Using java from external sources | update-alternatives | update-java-alternatives

After some problems with the jdk integrated in ubuntu 16.04 i installed the OpenJDK from http://jdk.java.net/9/.

The software is provided as tarball (tar.gz) and after
tar -xvf ~/Downloads/jdk-9+178_linux-x64_bin.tar.gz
the binaries can be used with
jdk-9/bin/java
...
But there are many links in /etc/alternatives still pointing to the ubuntu jdk:
lrwxrwxrwx 1 root root  41 Jul 11 21:02 /etc/alternatives/jar -> /usr/lib/jvm/java-9-openjdk-amd64/bin/jar
lrwxrwxrwx 1 root root  51 Jul 11 21:02 /etc/alternatives/jar.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/jar.1.gz
lrwxrwxrwx 1 root root  47 Jul 11 21:02 /etc/alternatives/jarsigner -> /usr/lib/jvm/java-9-openjdk-amd64/bin/jarsigner
lrwxrwxrwx 1 root root  57 Jul 11 21:02 /etc/alternatives/jarsigner.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/jarsigner.1.gz
lrwxrwxrwx 1 root root  42 Mai 31 21:09 /etc/alternatives/java -> /usr/lib/jvm/java-9-openjdk-amd64/bin/java
lrwxrwxrwx 1 root root  52 Mai 31 21:09 /etc/alternatives/java.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/java.1.gz
lrwxrwxrwx 1 root root  43 Jul 11 21:02 /etc/alternatives/javac -> /usr/lib/jvm/java-9-openjdk-amd64/bin/javac
lrwxrwxrwx 1 root root  53 Jul 11 21:02 /etc/alternatives/javac.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/javac.1.gz
lrwxrwxrwx 1 root root  45 Jul 11 21:02 /etc/alternatives/javadoc -> /usr/lib/jvm/java-9-openjdk-amd64/bin/javadoc
lrwxrwxrwx 1 root root  55 Jul 11 21:02 /etc/alternatives/javadoc.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/javadoc.1.gz
lrwxrwxrwx 1 root root  43 Jul 11 21:02 /etc/alternatives/javah -> /usr/lib/jvm/java-9-openjdk-amd64/bin/javah
lrwxrwxrwx 1 root root  53 Jul 11 21:02 /etc/alternatives/javah.1.gz -> /usr/lib/jvm/java-9-openjdk-amd64/man/man1/javah.1.gz
lrwxrwxrwx 1 root root  43 Jul 11 21:02 /etc/alternatives/javap -> /usr/lib/jvm/java-9-openjdk-amd64/bin/javap
You can change them manually by deleting and creating new links but i think this is to much work.
Update-Alternatives works, but you have to issue the following command many times:
update-alternatives --quiet --install /usr/bin/jconsole jconsole /home/data/opt/jdk-9/bin/jconsole 1191
Update-java-alternatives
update-java-alternatives.new -s java-jdk-9
update-java-alternatives.new: directory does not exist: /usr/lib/jvm/java-jdk-9
 does not work. But this can be fixed by creating your own jinfo file:
ls -la /usr/lib/jvm/.*jinfo
-rw-r--r-- 1 root root 2600 Mai  6 05:55 /usr/lib/jvm/.java-1.8.0-openjdk-amd64.jinfo
-rw-r--r-- 1 root root 2646 Apr 14  2016 /usr/lib/jvm/.java-1.9.0-openjdk-amd64.jinfo
-rw-r--r-- 1 root root 2058 Jul 14 22:05 /usr/lib/jvm/.java-jdk-9.jinfo
Just copy one of the existing files and change the paths to your JDK installation directory.
Then copy update-java-alternatives to update-java-alternatives and change the following lines:

inside the do_set function
#update-alternatives $uaopts --set $name $location
prio=$(awk -F= '/priority=/ {print $2}' $top/*$jname.jinfo)
update-alternatives $uaopts --install /usr/bin/${location##*\/} $name $location $prio
And then
update-java-alternatives.new -s java-jdk-9
will change all links in /etc/alternatives, so that running java without path will use the your installed version...
$ java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+178)
Java HotSpot(TM) 64-Bit Server VM (build 9+178, mixed mode)

Keine Kommentare:

Kommentar veröffentlichen