OpenJDK 11 was released on the 25th of September, 2018. As this is the first LTS release after version 8, it’s been awaited for long. After having it installed on Ubuntu 18.04 (Bionic Beaver), which comes with a package named openjdk-11-jdk, to my surprise that was still an earlier version (Java 10).
This is very simple, you just need the following package.
% apt-get install default-jdk
Nevertheless, do check what Java version does that actually install.
$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.2, mixed mode)
Surprise!
The Ubuntu Foundation Team made an
SRU exception for OpenJDK. Altought
version 10 is a non-LTS release, they’ve packaged it as openjdk-11-jdk
until OpenJDK 11 goes GA.
This choice was based on that assumption that there is a much smaller interface delta between releases 10 and 11
than it would be between 8 and 11.
That’s a fairly good reasoning and perhaps an apt-get upgrade
wouldn’t screw things up that badly when OpenJDK’s
version gets bumped up from 10 to 11.
There’s one area tiny though where there’s a significant difference between 10 and 11 and that’s that Flight Recorder got open sourced in the meantime. OpenJDK 10 doesn’t contain flight recorder, as at that time it was a commercial feature of Oracle JDK, but OpenJDK 11 does come with it.
As a consequence, installing openjdk-11-jdk
doesn’t allow applications to be instrumented with JFR, as the JVM options
used to enable it simply aren’t getting recognized by OpenJDK 10. In fact, the JVM fails to start and complains about
unrecognized options.
That’s easy too, you just have to download a tarball and extract it somewhere.
% wget https://download.java.net/java/GA/jdk11/28/GPL/openjdk-11+28_linux-x64_bin.tar.gz -O /tmp/openjdk-11+28_linux-x64_bin.tar.gz
% sudo tar xfvz /tmp/openjdk-11+28_linux-x64_bin.tar.gz --directory /usr/lib/jvm
% rm -f /tmp/openjdk-11+28_linux-x64_bin.tar.gz
That’s going to be OpenJDK 11 for real.
$ /usr/lib/jvm/jdk-11/bin/java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
I would prefer to use the distro’s JDK as long as it works for the task at hand. In this case, that isn’t an option, not yet at least. For that reason, I’m using the alternatives framework with which it’s possible to switch between JDKs easily.
% sudo sh -c 'for bin in /usr/lib/jvm/jdk-11/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done'
% sudo sh -c 'for bin in /usr/lib/jvm/jdk-11/bin/*; do update-alternatives --set $(basename $bin) $bin; done'
Once OpenJDK 11 appears in Ubuntu 18.04, it’s going to be just a matter of a package upgrade and an alternatives switch to use it.
% sudo apt-get install --only-upgrade default-jdk
% update-alternatives --config java
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/jdk-11/bin/java 100 manual mode
Press <enter> to keep the current choice[*], or type selection number:
If you like Java and Spring as much as I do, sign up for my newsletter.