It's super easy to have multiple versions of Java installed. Somewhat harder (read: tedious) is switching between versions at a whim.
tldr
- apt-get one
- untar the other
- export paths depending which one you want
apt-get one version
Decide which version you'll mostly be using. Or decide which one you want to have automatic updates. Or flip a coin, whatever. You don't even have to use apt-get
; just manually maintain both packages on your system (see next heading).
The point is: it's easier to use Ubuntu's package manager to maintain exactly one version of a package like java. You're gonna take care of the rest.
untar the other
Download a jdk tarball. Extract it to /opt
.
switch between them
I let the package manager handle my primary install. I export some vars for the other one when I need it. I work on the command line a lot, so it's an okay solution for me. I bother with:
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH
Also, I symlink jdk/
-> jdk1.6.0_3/
because I'm lazy and don't like reconfiguring my .bashrc and other scripts every incremental jdk upgrade.
Environment variables you might care about:
JAVA_LIBDIR
JNI_LIBDIR
JAVAJNI_LIBDIR
JVM_ROOT
JAVA_HOME
PATH
This is because those packages will become OpenJDK 11 when that is released. See this mailing list post:
On behalf of the Ubuntu Foundations Team, I am requesting an SRU
exception for OpenJDK. Our plan is to release OpenJDK 10 as the
default JRE/JDK 1 for Bionic, and then move the default JRE/JDK in
main to OpenJDK 11 in September/October 2018 as an SRU.
= Proposed Plan =
Bionic will be released with OpenJDK 10 as the default JRE/JDK and
OpenJDK 11 will replace it once it reaches GA.
...
If we are going to switch to OpenJDK 11 in bionic once released, we
want to avoid OpenJDK 8 as the default JRE/JDK in Bionic at release
time because any additional interface delta that exists between 8 and
11 not only exposes the archive to breakage, it also exposes external
consumers of the JDK to breakage. In comparison, the interface delta
between OpenJDK 10 and OpenJDK 11 is expected to be fairly small,
especially in comparison with the delta between OpenJDK 8 and OpenJDK
9 that we already know is large. We should therefore release with
OpenJDK 10 as the default JDK in 18.04, transitioning to OpenJDK 11
when it is released.
That's also why the source package of openjdk-11-*
is actually called openjdk-lts
.
A bug report has been filed - please subscribe to it (but don't comment unless you have new information to add, which is unlikely). An Ubuntu dev, Jeremy Bicha, has responded:
The intent is to upgrade openjdk-11 to 11 in Ubuntu 18.04 LTS. That's
why it was named that way. It is a major change and will take some
time to prepare. There is no need to ask for it to be done since it
will be done.
Ubuntu 18.04 LTS was released several months before OpenJDK 11 was
released so it wasn't possible to provide OpenJDK 11 before Ubuntu
18.04 LTS was released.
https://lists.ubuntu.com/archives/ubuntu-release/2018-March/004364.html
Sorry for the inconvenience.
2018-11-24: Please don't ask for an ETA. That sends out an email to everyone
subscribed to this bug and does not help fix the bug.
This bug is being worked on. openjdk 11.0.1 was updated in 18.10 and
there was a security update that needed to be handled quickly in 18.04
LTS. 11.0.1 will come to 18.04 LTS when it's ready but it is a major
change that needs careful coordination.
2019-02-26: This bug is already being handled in bug 1814133 so I'm marking it a duplicate. Further discussion should happen on that bug instead of here.
A new bug report has been opened for tracking all changes that need to be made, and there are a lot of them - a rough count of 140. Excerpts from the bug report:
This transition is a security update of openjdk-lts from openjdk-10 to
openjdk-11. This introduces runtime and FTBFS issues which requires
backports of multiple packages into the security pocket as well.
The packages are being build on PPAs under the
https://launchpad.net/~openjdk-11-transition team. The PPAs depend
solely on the security pocket and are separated in stages.
The agreed process among foundations and the security team is that
packages in the PPAs will be binary copied into bionic-proposed,
checked for migration issues, and - no issues pending - copied into
bionic-security.
[...]
A few packages might also need to be updated in Cosmic, but as an
exception that will be done after the Bionic transition is worked out.
And another Ubuntu dev, Tiago Stürmer Daitx noted:
[We] are planning to update java apps that are affected by this
transition.
To be more specific, any package that fails to run correctly with
openjdk-11 will be investigated and is a candidate for a update. The
update does not necessarily imply we will use the latest version: we
might simply apply or backport changes that allow them to work under
openjdk-11.
Still no ETA at present. Quite a few packages have been updated and added to the various PPAs maintained by the transition team, so if you wish to help out with testing, do check them out.
Update 17 April 2019:
It seems that fix has been released. Now apt show openjdk-11-jdk
shows:
Package: openjdk-11-jdk
Version: 11.0.2+9-3ubuntu1~18.04.3
And the output of java -version
is:
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
Best Answer
I've used a workaround suggested in the bugreport on launchpad @shz linked in the comment: