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

  • Such inconsistency happened couple of years ago which was fixed after some months. Also, as per Ubuntu Package search, unless you're using 18.04 running on non amd64/i386 device, the mentioned build isn't available in any supported release. Did you run sudo apt update before installing the package? Please [edit] your question and add the output of apt-cache policy openjdk-11-jdk. Also, mention the Ubuntu version you're using. – Kulfy Sep 27 '20 at 13:34
  • @Kulfy updated the question – YUVA PRASATH Sep 28 '20 at 05:32
  • Seems Ubuntu never updated JDK in main. What do you see under Updates in Software and updates app? Is there any option like bionic-security (I'm currently on 20.04, thus, cannot verify)? Is that enables? What is the output of grep security /etc/apt/sources.list? – Kulfy Sep 28 '20 at 17:24
  • @Kulfy selected everything under updates in Software and updates app. And now I'm able to install OpenJdk 11. – YUVA PRASATH Sep 28 '20 at 19:55
  • @Kulfy Thanks for the help – YUVA PRASATH Sep 28 '20 at 19:55
  • I have posted an answer. If that helped, you can mark that as accepted by clicking on grey check icon which would appear on the left of the answer. – Kulfy Sep 30 '20 at 08:29

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
  • 17,696
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"));')"