Installing OpenJDK 11 on Ubuntu 18.04
OpenJDK 11 was released this past week. Let's take a look at how to install OpenJDK 11 on Ubuntu 18.04, as well as new features in the JDK.
Join the DZone community and get the full member experience.
Join For FreeOpenJDK 11 was released on September 25, 2018. As this is the first LTS release after version 8, it's been a long time coming. 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 part of an earlier version (Java 10).
SRU Exception for OpenJDK
The Ubuntu Foundation Team made an SRU exception for OpenJDK. Although 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— Flight Recorder is now open source. OpenJDK 10 doesn't contain the flight recorder. At that time, it was a commercial feature of Oracle JDK, but OpenJDK 11 comes 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.
Installing Ubuntu's Default JDK
This is very simple, you just need the following package.
% apt-get install default-jdk
Nevertheless, be sure to check what Java version that actually installs.
$ 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)
Installing OpenJDK Manually
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
$ /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)
Switching Between JDKs
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, which makes it 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 just going to be a matter of a package upgrade and which alternative switches to use.
% 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:
Published at DZone with permission of Laszlo Csontos, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments