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.

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

17 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