Can not install jdk11 using update-alternatives --install
to try out the new features of jdk11 I installed it into /opt/ and want to use it using update-alternatives, like so:
sudo update-alternatives --install /etc/alternatives/java OpenJDK-11 /opt/jdk-11/bin/java 1102
which returns:
update-alternatives: using /opt/jdk-11/bin/javac to provide /etc/alternatives/java (OpenJDK-11) in auto mode
However, when I do
$ sudo update-alternatives --config java
I don't see the jdk I just installed. Instead I get a warning and the already existing choices:
update-alternatives: warning: /etc/alternatives/java has been changed (manually or by a script); switching to manual updates only
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1101 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
What does the warning mean, and why is it in fact showing both auto and manual mode entries? And why is my jdk11 not in there?
Solution 1:
Your first command was wrong, I think; it should have been:
sudo update-alternatives /usr/bin/java java /opt/jdk-11/bin/java 1102
and the same for all the others executables of the jdk.
how to do it
Install jdk-11
First install jdk-11 inside a directory in /usr/lib/jvm
. We will use openjdk-11+28-amd64
here
Create a shell script to udpate alternatives automatically
I call it jdk-11.sh
#!/bin/bash
if [[ $# -eq 0 ]] ;then
echo "Usage: jdk-11.sh [-i|-r]"
echo " -i install alternatives for jdk-11"
echo " -r remove alternatives for jdk-11"
exit -1
fi
install_dir="openjdk-11+28-amd64"
cmd=(java jexec jjs keytool pack200 rmid rmiregistry unpack200 jaotc jarsigner jar javac javadoc javap jcmd jdb jdeprscan jdeps jhsdb jimage jinfo jlink jmap jmod jps jrunscript jshell jstack jstatd jstat rmic serialver jconsole)
if [[ "$1" == "-i" ]] ;then
for c in ${cmd[@]}; do
update-alternatives --install /usr/bin/$c $c /usr/lib/jvm/$install_dir/bin/$c 1102
done
fi
if [[ "$1" == "-r" ]] ;then
for c in ${cmd[@]}; do
update-alternatives --remove $c /usr/lib/jvm/$install_dir/bin/$c
update-alternatives --auto $c
done
fi
Then make jdk-11.sh
executable, and run
sudo ./jdk-11.sh -i
to add alternatives for the new jdk-11
Switch to this jdk-11
then switch to that alternative with the help of update-java-alternatives
We need a helper file called .openjdk-11+28.jinfo
inside /usr/lib/jvm
name=openjdk-11+28-amd64
alias=openjdk-11+28-amd64
priority=1102
section=main
hl rmid /usr/lib/jvm/openjdk-11+28-amd64/bin/rmid
hl java /usr/lib/jvm/openjdk-11+28-amd64/bin/java
hl keytool /usr/lib/jvm/openjdk-11+28-amd64/bin/keytool
hl jjs /usr/lib/jvm/openjdk-11+28-amd64/bin/jjs
hl pack200 /usr/lib/jvm/openjdk-11+28-amd64/bin/pack200
hl rmiregistry /usr/lib/jvm/openjdk-11+28-amd64/bin/rmiregistry
hl unpack200 /usr/lib/jvm/openjdk-11+28-amd64/bin/unpack200
hl jexec /usr/lib/jvm/openjdk-11+28-amd64/lib/jexec
jdkhl jlink /usr/lib/jvm/openjdk-11+28-amd64/bin/jlink
jdkhl jdeps /usr/lib/jvm/openjdk-11+28-amd64/bin/jdeps
jdkhl rmic /usr/lib/jvm/openjdk-11+28-amd64/bin/rmic
jdkhl jinfo /usr/lib/jvm/openjdk-11+28-amd64/bin/jinfo
jdkhl jstat /usr/lib/jvm/openjdk-11+28-amd64/bin/jstat
jdkhl javac /usr/lib/jvm/openjdk-11+28-amd64/bin/javac
jdkhl jhsdb /usr/lib/jvm/openjdk-11+28-amd64/bin/jhsdb
jdkhl jps /usr/lib/jvm/openjdk-11+28-amd64/bin/jps
jdkhl jstack /usr/lib/jvm/openjdk-11+28-amd64/bin/jstack
jdkhl jrunscript /usr/lib/jvm/openjdk-11+28-amd64/bin/jrunscript
jdkhl javadoc /usr/lib/jvm/openjdk-11+28-amd64/bin/javadoc
jdkhl jmod /usr/lib/jvm/openjdk-11+28-amd64/bin/jmod
jdkhl javap /usr/lib/jvm/openjdk-11+28-amd64/bin/javap
jdkhl jar /usr/lib/jvm/openjdk-11+28-amd64/bin/jar
jdkhl jaotc /usr/lib/jvm/openjdk-11+28-amd64/bin/jaotc
jdkhl jshell /usr/lib/jvm/openjdk-11+28-amd64/bin/jshell
jdkhl jmap /usr/lib/jvm/openjdk-11+28-amd64/bin/jmap
jdkhl jdeprscan /usr/lib/jvm/openjdk-11+28-amd64/bin/jdeprscan
jdkhl jimage /usr/lib/jvm/openjdk-11+28-amd64/bin/jimage
jdkhl jstatd /usr/lib/jvm/openjdk-11+28-amd64/bin/jstatd
jdkhl jdb /usr/lib/jvm/openjdk-11+28-amd64/bin/jdb
jdkhl serialver /usr/lib/jvm/openjdk-11+28-amd64/bin/serialver
jdkhl jcmd /usr/lib/jvm/openjdk-11+28-amd64/bin/jcmd
jdkhl jarsigner /usr/lib/jvm/openjdk-11+28-amd64/bin/jarsigner
jdk jconsole /usr/lib/jvm/openjdk-11+28-amd64/bin/jconsole
Then run
sudo update-java-alternatives -s openjdk-11+28-amd64
To roll-back to ubuntu package
sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
sudo ./jdk-11.sh -r # optionnal
sudo rm -rf /usr/lib/jvm/openjdk-11+28-amd64 # optionnal