Update April 2018: Oracle Java 9 has reached end of life and its binaries are no longer available to download, so the installer in this article won't work. Use Oracle Java 17 LTS instead.
Update September 25, 2017: Oracle JDK 9 is now considered stable. There are currently only 64bit builds available in the PPA (no other builds are available for download).
Because I've received quite a few requests for this, you can now install the latest Oracle Java 9 (early access release) in all supported Ubuntu / Linux Mint versions, by using the WebUpd8 Oracle Java PPA.
Because I've received quite a few requests for this, you can now install the latest Oracle Java 9 (early access release) in all supported Ubuntu / Linux Mint versions, by using the WebUpd8 Oracle Java PPA.
For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release (it should be released in 2016)! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps.
Reminder: the WebUpd8 Oracle Java PPA doesn't include any Oracle Java binaries because that's not allowed by the Oracle Java license, that's why the PPA provides an installer that automatically downloads the latest Oracle Java 9 (JDK9 and the Java 9 browser plugin) and sets up everything for you. Also, the Oracle Java 9 Installer is considered to be alpha quality and is offered without any guarantees, so use it at your own risk!
It's also important to mention that the Oracle Java 9 download servers are pretty slow (and it's even slower to start), so even with a fast Internet connection, the download may take a while or it may fail (so you'll have try again) and there's nothing I can do about that.
If you want to install Oracle Java 8 instead (which is considered stable), see these articles: Ubuntu / Linux Mint | Debian.
Install Oracle Java 9 (JDK9) in Ubuntu, Linux Mint or Debian via PPA
To add the WebUpd8 Oracle Java PPA and install Oracle Java 9 in all supported Ubuntu / Linux Mint versions, use the following commands:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer
To install Oracle Java 9 in Debian, you can setup "add-apt-repository" as we've explained a while back and use the Ubuntu installation instructions above. You can also manually add the repository and key and install Oracle Java 9 in Debian using the following commands:
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java9-installer
exit
-----------------------------------------------------------
Update October 20, 2016:
Previously, this package would increment the Java priority to make it default. The oracle-java9-installer package now sets the Java priority to 1091, and that may or may not set it as default, depending on other Java packages you may have installed (for instance, if Java 8 is also installed, Java 9 becomes default, but if Java 10 is installed, that will become default).
To make Java 9 default, you must install the "oracle-java9-set-default" package (which configures the Java environment variables and sets it as default), which I added as a "Recommended" package to "oracle-java9-installer".
In Ubuntu, recommended packages are automatically installed, so "oracle-java9-set-default" should be installed when installing "oracle-java9-installer". In Linux Mint on the other hand, recommended packages are not installed by default, so you must install this package manually if you want to set Oracle Java 9 as default.
So, if you want to set Oracle Java 9 as default, no matter what other Java versions are installed, make sure that you install the oracle-java9-set-default package (which, again, should be automatically installed with the main Oracle Java Installer package in Ubuntu, but not in Linux Mint):
If you don't want to make Oracle Java 9 default (it might still be set as default, depending on what other Java versions you may have installed), install the oracle-java9-installer with "--no-install-recommends":
Note: removing the oracle-java9-set-default package does not undo all the changes (I have yet to find a way to do this properly). If you don't want to set it as default, remove both oracle-java8-installer and oracle-java8-set-default packages, and then install oracle-java8-installer with "--no-install-recommends" (like mentioned above).
Update October 20, 2016:
Previously, this package would increment the Java priority to make it default. The oracle-java9-installer package now sets the Java priority to 1091, and that may or may not set it as default, depending on other Java packages you may have installed (for instance, if Java 8 is also installed, Java 9 becomes default, but if Java 10 is installed, that will become default).
To make Java 9 default, you must install the "oracle-java9-set-default" package (which configures the Java environment variables and sets it as default), which I added as a "Recommended" package to "oracle-java9-installer".
In Ubuntu, recommended packages are automatically installed, so "oracle-java9-set-default" should be installed when installing "oracle-java9-installer". In Linux Mint on the other hand, recommended packages are not installed by default, so you must install this package manually if you want to set Oracle Java 9 as default.
So, if you want to set Oracle Java 9 as default, no matter what other Java versions are installed, make sure that you install the oracle-java9-set-default package (which, again, should be automatically installed with the main Oracle Java Installer package in Ubuntu, but not in Linux Mint):
sudo apt-get install oracle-java9-set-default
If you don't want to make Oracle Java 9 default (it might still be set as default, depending on what other Java versions you may have installed), install the oracle-java9-installer with "--no-install-recommends":
sudo apt-get install --no-install-recommends oracle-java9-installer
Note: removing the oracle-java9-set-default package does not undo all the changes (I have yet to find a way to do this properly). If you don't want to set it as default, remove both oracle-java8-installer and oracle-java8-set-default packages, and then install oracle-java8-installer with "--no-install-recommends" (like mentioned above).
-----------------------------------------------------------
Tip: if you're behind a firewall / router that blocks some of the redirects required to download the Oracle Java archive, you can download the JDK tar.gz archive manually and place it under /var/cache/oracle-jdk9-installer - then, installing the "oracle-java9-installer" package will use the local archive instead of trying it to download it itself.
After installing the package, you can check the Java version by running "java -version" in a terminal, which should display an output similar to this:
After installing the package, you can check the Java version by running "java -version" in a terminal, which should display an output similar to this:
andrei@andrei-desktop:~$ java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Or, "javac -version":andrei@andrei-desktop:~$ javac -version
javac 9
And so on.Automated installation (auto accept license)
The Oracle Java 9 Installer prompts you to accept the Oracle license before proceeding with the installation and it's only required once, so you don't have to accept the license with each update. If you want to automate the installation process, you can use the command below to automatically accept the Oracle Java 9 license:
echo oracle-java9-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
Update: if the command above doesn't work, use the following (thanks to Adam!):
echo oracle-java8-installer shared/accepted-oracle-licence-v1-1 boolean true | sudo /usr/bin/debconf-set-selections
Update: if you're looking for Oracle Java 10, you can find it in a different PPA - see this ARTICLE for info. The same goes for Oracle Java 11, for which you'll find installation instructions for Debian or Ubuntu HERE.