How To Install Oracle Java 11 In Ubuntu, Linux Mint Or Debian (From PPA Repository)

Oracle Java 11, the first long term support release, can now be installed in Ubuntu, Linux Mint and Debian from the Linux Uprising Java PPA. For what's new in the latest JDK11, read the release notes.

It's important to note that with Java 11, Oracle uses a new, commercial license. It can be downloaded and used without cost only for development and testing only, and it requires paying a fee if it's used in production:

You may not: use the Programs for any data processing or any commercial, production, or internal business purposes other than developing, testing, prototyping, and demonstrating your Application.

This quote is from the Oracle Java SE license (via).

As a result, you should only use Oracle JDK if you intend to pay for it. Use OpenJDK, which is available in the Debian / Ubuntu repositories, for anything else. From Java 11 forward, Oracle JDK builds and OpenJDK builds are essentially identical with a few differences you can read about here.

Oracle Java 11 is available to download as a DEB package, but all the package does is install the files to /usr/lib/jvm/jdk-11, just like it would be if you copied the extracted directory there, without any options to set it as default / update the Java alternatives, set environment variables and so on.

The Oracle Java installer from the Linux Uprising PPA can set Java 11 as default, set environment variables (JAVA_HOME, etc.) and easily undo this. The installer downloads Oracle Java 11 (64bit only as that's what Oracle provides) from Oracle's servers because the license doesn't allow uploading the binary to the PPA.

The package in this PPA uses the Web Upd8 Java package installer as a base, but it's modified to install the latest Oracle JDK 11.

If you decide to use OpenJDK instead of Oracle Java: Users running Ubuntu 18.04 or older can install OpenJDK by using an official Ubuntu PPA. You might notice there's an openjdk-11-jdk package in Ubuntu 18.04 (and Linux Mint 19), but that package actually contains OpenJDK 10. The PPA I mentioned provides the actual OpenJDK 11 package. See this article for more information and installation instructions: How To Install OpenJDK 11 In Ubuntu 18.04, 16.04 or 14.04 / Linux Mint 19, 18 or 17.

Install Oracle Java 11 (JDK 11) in Ubuntu, Linux Mint or Debian from PPA


Oracle Java 11 Ubuntu

To add the LinuxUprising Java PPA repository to your software sources and install Oracle Java 11 in Ubuntu or Linux Mint (64bit only) you can use the commands below:

sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-installer

In Debian (64bit only) you can add the repository and install Oracle Java 11 using these commands:

su -
echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | tee /etc/apt/sources.list.d/linuxuprising-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
apt-get update
apt-get install oracle-java11-installer
exit

The oracle-java11-installer package has a Recommends field for the oracle-java11-set-default package, which sets Oracle Java 11 as default (including setting the JAVA_HOME environment variable, which requires a session restart). Such recommended packages are installed automatically on Ubuntu, but are not on other Debian-based Linux distributions.

So to make Oracle Java 11 default, install the oracle-java11-set-default package:

sudo apt install oracle-java11-set-default

If you want to have Oracle Java 11 installed but not set it as the default Java, make sure the oracle-java11-set-default package is not installed / remove it:

sudo apt remove oracle-java11-set-default

You can check to see if Oracle Java 11 is set as default by checking your current Java version using the following command:

java -version

If Oracle Java 11 is default, you should see an output similar to the following:

java version "11" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

You can try it for javac as well:

javac -version

Which should return an output similar to the one below:

javac 11

This package supports installing Java 11 by manually downloading the archive. This is useful in case you're behind a firewall or your ISP somehow blocks the Oracle JDK 11 download link (so you can download it from a different computer, etc.). To do this, download the Oracle Java 11 tar.gz archive and place it in the /var/cache/oracle-jdk11-installer folder. Next, install the oracle-java11-installer package using the regular instructions and it should pick up the downloaded tar.gz archive instead of downloading it.

Automatically accept the Oracle Java 11 lincense (for automated installations)


By default, the Oracle Java 11 installer prompts you to accept the Oracle Java license before proceeding with the JDK 11 installation. If you want to automate the Oracle Java 11 installation process, use the following command to automatically accept the license:

echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | sudo /usr/bin/debconf-set-selections

If the command above doesn't automatically accepts the Oracle Java 11 license, try the command below instead:

echo oracle-java11-installer shared/accepted-oracle-licence-v1-2 boolean true | sudo /usr/bin/debconf-set-selections

28 comments:

  1. I keep getting: "Connecting to edelivery.oracle.com (edelivery.oracle.com)|2001:418:1456:aa0::2d3e|:443... failed: Permission denied."

    Same with Java 10. Not sure what's causing this.

    ReplyDelete
    Replies
    1. Are you able to download it using a web browser from here? It could be a proxy / firewall / network issue.

      As a work-around, if you can manually download the Oracle Java .tar.gz, you can place it in /var/cache/oracle-jdk11-installer and when you run "sudo apt install oracle-java11-installer" it will use the file from that directory instead of downloading the archive from Oracle's website.

      Delete
    2. mm. There already seems to be a jdk-11_linux-x64_bin.tar.gz in that directory. When I run "sudo apt install oracle-java11-installer", it still tries to connect and I get permission denied.

      Delete
    3. That file may exist but it's probably empty or incomplete. Also, I updated the package so now you'll need the latest 11.0.1 version (jdk-11.0.1_linux-x64_bin.tar.gz). If you manually download that archive and place it in the folder I mentioned, it should work.

      Delete
    4. hello where is the box to accept the agreement in the java page?

      Delete
  2. Thank you for the article and guide, worked perfectly on Linux Mint 19 XFCE :)

    ReplyDelete
  3. Well, you were partially right :)
    The file was there, but empty. I downloaded 11.0.1 and put it in the correct directory, but running "sudo apt install oracle-java11-installer" still gives me
    Connecting to edelivery.oracle.com (edelivery.oracle.com)|2600:141b:2000:28a::2d3e|:443... failed: Permission denied.

    ReplyDelete
    Replies
    1. Awright, I'm an idiot. Had to add oracle.com to my whitelist. Now I've got a different issue:

      download failed
      Oracle JDK 10 is NOT installed.

      So I guess I have to go to 10 first, then 11?

      Delete
    2. Remove oracle-java10-installer. Oracle no longer provides public downloads for Oracle Java 10 so that won't work. So just do: "sudo apt remove oracle-java10-installer". Then follow the steps I mentioned.

      This is a screenshot showing oracle-java11-installer using the local .tar.gz file instead of downloading it from Oracle: https://i.imgur.com/5g0J9Kj.png.

      Delete
  4. I don't think you get near enough thanks for making this so easy to find and easy to do. I just wanted you to know how much I appreciate it. - Ken Starks Reglue.

    ReplyDelete
  5. yo I want to know what files do you edit to implement the $JAVA_HOME ?

    I cannot found the settings on my bashrc bash_profile profile or /etc/environment

    ReplyDelete
    Replies
    1. If you install the oracle-java11-set-default package, it adds jdk.sh in /etc/profile.d/ which sets JAVA_HOME and others. A logout/login is needed after installing the oracle-java11-set-default package to pick up the new environment variables.

      Delete
  6. Hello! How do I remove the Oracle JDK 11 installation? I followed the installation steps successfully, but now I want to remove ...

    ReplyDelete
    Replies
    1. You can remove it using:

      sudo apt remove oracle-java11-installer

      Delete
    2. Thank you! It worked!
      But do I need to worry about the PPA repository that has been added?

      Delete
    3. If you want to remove the repository you can do this using Software & Updates > Other Software > disable the linuxuprising/java PPA. Or you can remove it from the command line, like so:

      sudo add-apt-repository -r ppa:linuxuprising/java

      Delete
  7. the installation failed because Oracle JDK 11 got updated to jdk-11.0.2 and jdk-11.0.1 isn't available for download anymore, thank you for PPA repository and waiting for the update

    ReplyDelete
    Replies
    1. The PPA now has the latest Oracle Java 11.0.2 and the installer should work again.

      Delete
  8. Logix -

    Can you please update the post install script?
    I was able to install 11.0.2 (Minor Version 7) by modifying the post install script (when 11.0.1 broke) like this ...

    # diff /var/lib/dpkg/info/oracle-java11-installer.postinst /var/lib/dpkg/info/oracle-java11-installer.postinst.ORIGINAL
    25c25
    < SHA256SUM_TGZ="1f14572cae12adec64d28fdbf38935df7ced20b3efb54c33934b8bbecafdcd79" #must be modified for each release
    ---
    > SHA256SUM_TGZ="e7fd856bacad04b6dbf3606094b6a81fa9930d6dbb044bbd787be7ea93abc885" #must be modified for each release
    63,64c63,64
    < JAVA_VERSION_2nd_PART=0.2 #
    < JAVA_VERSION_MINOR=7 #must be modified for each release
    ---
    > JAVA_VERSION_2nd_PART=0.1 #
    > JAVA_VERSION_MINOR=13 #must be modified for each release
    67c67
    < PARTNER_URL="http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION}.${JAVA_VERSION_2nd_PART}+${JAVA_VERSION_MINOR}/f51449fcd52f4d52b93a989c5c56ed3c/$FILENAME"
    ---
    > PARTNER_URL="http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION}.${JAVA_VERSION_2nd_PART}+${JAVA_VERSION_MINOR}/90cf5d8f270a4347a95050320eef3fb7/$FILENAME"
    70,71c70,71
    < JAVA_VERSION_2nd_PART=0.2 #
    < JAVA_VERSION_MINOR=7 #must be modified for each release
    ---
    > JAVA_VERSION_2nd_PART=0.1 #
    > JAVA_VERSION_MINOR=13 #must be modified for each release
    74c74
    < PARTNER_URL="http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION}.${JAVA_VERSION_2nd_PART}+${JAVA_VERSION_MINOR}/f51449fcd52f4d52b93a989c5c56ed3c/$FILENAME"
    ---
    > PARTNER_URL="http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION}.${JAVA_VERSION_2nd_PART}+${JAVA_VERSION_MINOR}/90cf5d8f270a4347a95050320eef3fb7/$FILENAME"

    ReplyDelete
    Replies
    1. Thank you.
      I won't have time to check it out for a while, but the community thanks you. Keep up the good work.

      Delete
  9. I've tried a couple times installing java 11 using this PPA and it always returned 404 Not Found.

    ReplyDelete
    Replies
    1. Java was updated and when Oracle does this, it removes the old URLs, that's why you got a 404 not found error. I just updated the packages with the new Oracle Java 11.0.2 so it will work now. Use "sudo apt update" to update the software sources, then "sudo apt install oracle-java11-installer" to install the latest version.

      Delete
  10. The installation failed. It said:
    E: Unable to locate package oracle-java11-installer

    ReplyDelete
    Replies
    1. The oracle-java11-installer package is in the PPA for all supported Ubuntu versions: https://launchpad.net/~linuxuprising/+archive/ubuntu/java/+packages.

      The reason you're getting the "unable to locate package" error might be due to:
      - you didn't add the PPA (sudo add-apt-repository ppa:linuxuprising/java)
      - you didn't update the software sources (sudo apt update)
      - you're running an unsupported Ubuntu version (or some Linux distribution based on an unsupported Ubuntu version)

      What Ubuntu version are you on?

      Delete
  11. There is an error with the .desktop file: "/usr/share/applications/JB-javaws-jdk11.desktop".
    Internally, is pointing to java 11 icon, jvm, etc. The content of the file is:

    [Desktop Entry]
    Encoding=UTF-8
    Name=Oracle Java 10 Web Start
    Comment=Oracle Java 10 Web Start
    Exec=/usr/lib/jvm/java-10-oracle/bin/javaws %u
    Terminal=false
    Type=Application
    Icon=oracle_java10
    Categories=Application;Network;
    MimeType=application/x-java-jnlp-file;

    It should be:

    [Desktop Entry]
    Encoding=UTF-8
    Name=Oracle Java 11 Web Start
    Comment=Oracle Java 11 Web Start
    Exec=/usr/lib/jvm/java-11-oracle/bin/javaws %u
    Terminal=false
    Type=Application
    Icon=oracle_java11
    Categories=Application;Network;
    MimeType=application/x-java-jnlp-file;

    ReplyDelete
    Replies
    1. I actually should have deleted that file, since there's no javaws in Oracle Java 11. I'll update the package with that and a couple other minor changes.

      Delete