Install Any Oracle Java (JDK) Version In Ubuntu, Debian, Linux Mint Or Fedora With install-java.sh

"install-java.sh" is a Bash script for installing and setting up any Oracle Java Development Kit (JDK) version on Debian and Ubuntu based Linux distributions.

The script developer is says he's mainly using Ubuntu, and therefore the script was only tested on Ubuntu however, I used the script to install and set up Oracle Java on Fedora, and it worked without any issues. It might work on other Linux distributions too.

The install-java.sh script is quite versatile, allowing users to install any Oracle JDK major / minor version. You can use it to:

install Oracle Java 7, 10 and other JDK versions that are now only available to Oracle Customers through My Oracle Support (requires support login)

install an Oracle Java build for a different architecture than the system the script runs on

Thanks to this, install-java.sh is a great alternative to the Oracle Java 8 PPA maintained by Web Upd8, or the Oracle Java 11 PPA which I maintain, allowing users to install not only the latest Oracle Java version, but any version they desire. And it works on Fedora and probably other Linux distributions too, and not just Ubuntu/Debian.

The script does not support installing JDK 12 snapshots, but those are OpenJDK builds (there are no Oracle Java 12 snapshots available yet as far as I know).

install-java.sh script features include:

you can automate the Java installation script

specify the installation directory (defaults to /usr/lib/jvm)

can install Oracle JDK demos and JCE policy files, which are available with Oracle Java up to version 8 (to install these, download the demos Linux .tar.gz and JCE policy .zip archives and place them in the same folder as the Oracle Java .tar.gz, then run the install command as usual, and it will pick up these, asking you if you want to install them)

can install a menu entry (shortcut) for Oracle Java Mission Control (JMC)

comes with an uninstall-java.sh script to uninstall any Java version installed using install-java.sh

-f specifies the Oracle Java .tar.gz archive and the path to it, and -p lets you set the Oracle Java installation directory (a new Java subfolder is created in this directory), with /usr/lib/jvm being the default installation path. I used sudo -E (preserve user environment when running command) because without it, the JAVA_HOME environment variable was not set on Fedora.

Example. I downloaded Oracle JDK 8u202, and the .tar.gz is saved in the Downloads folder. This command installs the downloaded Oracle JDK 8u202 in /usr/lib/jvm:

As you can see, the script asks if it should run update-alternatives for the Oracle Java binaries (and set this Oracle Java version as the default system Java), set the JAVA_HOME environment variable in your ~/.bashrc file, and if it should create a desktop shortcut for Oracle Java Mission Control (JMC).

Automating the Oracle Java installation process with install-java.sh

You can automate the Oracle Java installation (useful if you want to run the installation from a script) when using the install-java.sh script by using the yes command, like this (which answers yes to all the install-java.sh script questions - see above):

Up until version 8, Oracle Java had demos and Java Cryptography Extension (JCE) unlimited strength jurisdiction policy files available for download. If you need to install these as well, the archives can be extracted and installed by install-java.sh, when installing Oracle Java.

Download Oracle Java, the demos archive (same version as Oracle Java), and the JCE policy files, and place all of them in the same folder.

Download the .tar.gz archives for Oracle Java 8u202 and the demos, and the JCE policy zip, put them in a folder called "java" in your home, then install Oracle Java as you would normally with install-java.sh, and the demos and JCE policy will be installed along with Oracle Java. Example install command in this case:

java_dist_dir is the folder where Oracle Java was installed. For example, /usr/lib/jvm/jdk1.8.0_202 for Oracle Java 8u202. The uninstall-java.sh script updates the Java alternatives, removes the installed Java directory, and removes the JMC shortcut.