2

I used the below apt command to install OpenJDK 11

sudo apt install openjdk-11-jdk

But, OpenJDK 10 got installed, result of java --version

openjdk 10.0.1 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)

After apt update Output of sudo apt-cache policy openjdk-11-jdk

openjdk-11-jdk:
  Installed: 10.0.1+10-3ubuntu1
  Candidate: 10.0.1+10-3ubuntu1
  Version table:
 *** 10.0.1+10-3ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status

How to install OpenJDK 11?

Ubuntu version: 18.04

2 Answers2

3

This is a known issue in OpenJDK 11 version 10.0.1+10-3ubuntu1 provided by bionic/main repository. An updated version 11.0.8+10-0ubuntu1~18.04.1 is available in bionic-updates as well as bionic-security which wasn't pushed in bionic/main. You may consider enabling at least one of the said repository to install the updated version.

You can enable them from Software and Updates→Updates or append them directly in sources.list using tee. For that run,

echo "deb http://archive.ubuntu.com/ubuntu bionic-updates main" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu bionic-security main" | sudo tee -a /etc/apt/sources.list

Once done, run sudo apt update and retry installing/updating OpenJDK 11.

Kulfy
  • 18,154
1

Your problem is that there already was a JDK installed and installing new one didn't automatically set it to current version.

Here is a link to the post describing how to set Java version: Switch between multiple java versions


This is what I have found working:

apt install doesn't configure the Java version, if there already exist one.

If the openjdk-11 got installed, you can switch to this like that:

sudo update-alternatives --config java

This shows you a table of JDK's installed, pick the the correct one from the list with enter.

Also, you might want to change $JAVA_HOME environment variable, to by running:

export JAVA_HOME="$(jrunscript -e java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"