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 the latest Oracle Java 11 LTS
  • install any Oracle Java 8 version, including Oracle Java demos and the JCE policy
  • 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/12 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.

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

Related:


Using install-java.sh to install Oracle Java in Debian, Ubuntu, Linux Mint and Fedora


Oracle Java Linux install script

1. Download install-java.sh and make it executable.

As a general rule, I recommend checking out the code used in this script and any other scripts you run on your system, and only run them if you have at least some basic understanding of what they do.

You can download install-java.sh in your home directory, and make it executable using:

cd && wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh

chmod +x install-java.sh

2. Install unzip (required by the install-java.sh script).

unzip can be installed as follows:

  • Debian, Ubuntu, Linux Mint:
sudo apt install unzip

  • Fedora:
sudo dnf install unzip

2. Use install-java.sh to install Oracle Java (JDK 7, 8 or 11).

To install Oracle Java, you'll need to download the .tar.gz archive from oracle.com. Then you can install Oracle Java 11, 8 or 7 using this command:

sudo -E ./install-java.sh -f </path/to/oracle-java.tar.gz> -p </usr/lib/jvm>

-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:

sudo -E ./install-java.sh -f ~/Downloads/jdk-8u202-linux-x64.tar.gz -p /usr/lib/jvm

This is the command with its output, so you can see what's going on when installing Oracle Java using the install-java.sh script:

$ sudo -E ./install-java.sh -f ~/Downloads/jdk-8u202-linux-x64.tar.gz -p /usr/lib/jvm

Extracting /home/logix/Downloads/jdk-8u202-linux-x64.tar.gz to /usr/lib/jvm
JDK is extracted to /usr/lib/jvm/jdk1.8.0_202
Run update-alternatives commands? [y/N] y
Running update-alternatives --install and --config for jar java javac javadoc javah javap javaws jcmd jconsole jarsigner jhat jinfo jmap jmc jps jstack jstat jstatd jvisualvm keytool policytool wsgen wsimport mozilla-javaplugin.so
Do you want to set JAVA_HOME environment variable? [y/N] y
Do you want to create a desktop shortcut to JMC? [y/N] y

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):

yes | sudo -E ./install-java.sh -f </path/to/oracle-java.tar.gz> -p </usr/lib/jvm>

Installing Oracle Java demos and JCE policy with install-java.sh (JDK 7 or 8 only)


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.

Example for Oracle Java 8u202:


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:

sudo -E ./install-java.sh -f ~/java/jdk-8u202-linux-x64.tar.gz -p /usr/lib/jvm

The script will ask you if you want to install the demos and JCE policy files before proceeding to installing Oracle Java:

$ sudo -E ./install-java.sh -f ~/java/jdk-8u202-linux-x64.tar.gz -p /usr/lib/jvm

Extracting /home/logix/java/jdk-8u202-linux-x64.tar.gz to /usr/lib/jvm
JDK is extracted to /usr/lib/jvm/jdk1.8.0_202
Extract demos? [y/N] y
Extracting /home/logix/java/jdk-8u202-linux-x64-demos.tar.gz to /usr/lib/jvm
Install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files? [y/N] y
Extracting policy jars in /home/logix/java/jce_policy-8.zip to /usr/lib/jvm/jdk1.8.0_202/jre/lib/security
Archive:  /home/logix/java/jce_policy-8.zip
  inflating: /usr/lib/jvm/jdk1.8.0_202/jre/lib/security/local_policy.jar  
  inflating: /usr/lib/jvm/jdk1.8.0_202/jre/lib/security/US_export_policy.jar  
Run update-alternatives commands? [y/N] y
Running update-alternatives --install and --config for jar java javac javadoc javah javap javaws jcmd jconsole jarsigner jhat jinfo jmap jmc jps jstack jstat jstatd jvisualvm keytool policytool wsgen wsimport mozilla-javaplugin.so
Do you want to set JAVA_HOME environment variable? [y/N] y
Do you want to create a desktop shortcut to JMC? [y/N] y

Uninstalling Oracle Java installed with install-java.sh


To uninstall Oracle Java there's another script, called uninstall-java.sh. You can download the script in your home directory, make it executable, and uninstall Oracle Java like this:

cd && wget https://raw.githubusercontent.com/chrishantha/install-java/master/uninstall-java.sh

chmod +x uninstall-java.sh

sudo -E ./uninstall-java.sh -p <java_dist_dir>

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.

Example:

$ sudo -E ./uninstall-java.sh -p /usr/lib/jvm/jdk1.8.0_202

Run update-alternatives commands? [y/N] y
Running update-alternatives --remove for jar java javac javadoc javah javap javaws jcmd jconsole jarsigner jhat jinfo jmap jmc jps jstack jstat jstatd jvisualvm keytool policytool wsgen wsimport mozilla-javaplugin.so
Remove directory '/usr/lib/jvm/jdk1.8.0_202'? [y/N] y
Remove JMC shortcut? [y/N] y