Oracle Java 10 JDK and JRE installation scripts for macOS
Oracle has started to release Java 10 for macOS, so I’m posting a couple of scripts to download and install the following:
Oracle has been releasing two separate versions of Java 8 simultaneously and may do the same for Java 10, so these Java 10-focused scripts are designed to allow the user to set which version they want to install: the CPU release or the PSU release.
The difference between CPU and PSU releases is as follows:
- Critical Patch Update (CPU): contains both fixes to security vulnerabilities and critical bug fixes.
- Patch Set Update (PSU): contains all the fixes in the corresponding CPU, plus additional fixes to non-critical problems.
For more details on the differences between CPU and PSU updates, please see the link below:
http://www.oracle.com/technetwork/java/javase/cpu-psu-explained-2331472.html
For more information, please see below the jump.
The scripts are available on GitHub via the links below:
Oracle Java 10 JDK: https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/install_latest_oracle_java_jdk_10
Oracle Java 10 JRE: https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/install_latest_oracle_java_jre_10
The scripts are also available as payload-free packages, compressed and stored as .zip files in the payload_free_package directory available via the links above.
Oracle Java 10 JDK script:
The script below will download a disk image containing the latest version of the Java 10 JDK from Oracle and install the JDK using the installer package stored inside the downloaded disk image.
How the script works:
- Verifies that the Mac is running a Java 10-compatible operating system
- Uses curl to download a disk image containing the latest Java 10 JDK installer from Oracle’s web site
- Renames the downloaded disk image to java_ten_jdk.dmg and stores it in /tmp.
- Mounts the disk image silently in /tmp. The mounted disk image will not be visible to any logged-in user.
- Installs the latest Java 10 JDK using the installer package stored inside the disk image.
- After installation, unmounts the disk image and removes it from the Mac in question.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script downloads and installs the latest available Oracle Java 10 JDK CPU release or PSU release for compatible Macs | |
#Set error status | |
error=0 | |
# Determine OS version | |
osvers=$(sw_vers -productVersion | awk -F. '{print $2}') | |
IdentifyLatestJDKRelease(){ | |
# Determine the download URL for the latest CPU release or PSU release. | |
Java_10_JDK_CPU_URL=$(/usr/bin/curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html | grep -ioE "http://download.oracle.com/otn-pub/java/jdk/.*?/jdk-10.*?.dmg" | head -1) | |
Java_10_JDK_PSU_URL=$(/usr/bin/curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html | grep -ioE "http://download.oracle.com/otn-pub/java/jdk/.*?/jdk-10.*?.dmg" | tail -1) | |
# Use the Version variable to determine if the script should install the latest CPU release or PSU release. | |
if [[ "$Version" = "PSU" ]] && [[ "$Java_10_JDK_PSU_URL" != "" ]]; then | |
fileURL="$Java_10_JDK_PSU_URL" | |
echo "Installing Oracle Java 10 JDK Patch Set Update (PSU) –" "$Java_10_JDK_PSU_URL" | |
elif [[ "$Version" = "PSU" ]] && [[ "$Java_10_JDK_PSU_URL" = "" ]]; then | |
echo "Unable to identify download URL for requested Oracle Java 10 JDK Patch Set Update (PSU). Exiting." | |
error=1 | |
exit "$error" | |
fi | |
if [[ "$Version" = "CPU" ]] && [[ "$Java_10_JDK_CPU_URL" != "" ]]; then | |
fileURL="$Java_10_JDK_CPU_URL" | |
echo "Installing Oracle Java 10 JDK Critical Patch Update (CPU) –" "$Java_10_JDK_PSU_URL" | |
elif [[ "$Version" = "CPU" ]] && [[ "$Java_10_JDK_CPU_URL" = "" ]]; then | |
echo "Unable to identify download URL for requested Oracle Java 10 JDK Critical Patch Update (CPU). Exiting." | |
error=1 | |
exit "$error" | |
fi | |
} | |
if [[ ${osvers} -lt 10 ]]; then | |
echo "Oracle Java 10 JDK is not available for Mac OS X 10.9.5 or earlier." | |
fi | |
if [[ ${osvers} -ge 10 ]]; then | |
# Specify name of downloaded disk image | |
java_ten_jdk_dmg="/tmp/java_ten_jdk.dmg" | |
# Use the Version variable to set if you want to download the latest CPU release or the latest PSU release. | |
# The difference between CPU and PSU releases is as follows: | |
# | |
# Critical Patch Update (CPU): contains both fixes to security vulnerabilities and critical bug fixes. | |
# | |
# Patch Set Update (PSU): contains all the fixes in the corresponding CPU, plus additional fixes to non-critical problems. | |
# | |
# For more details on the differences between CPU and PSU updates, please see the link below: | |
# | |
# http://www.oracle.com/technetwork/java/javase/cpu-psu-explained-2331472.html | |
# | |
# Setting the variable as shown below will set the script to install the CPU release: | |
# | |
# Version=CPU | |
# | |
# Setting the variable as shown below will set the script to install the PSU release: | |
# | |
# Version=PSU | |
# | |
# By default, the script is set to install the CPU release. | |
Version=CPU | |
# Identify the URL of the latest Oracle Java 10 JDK software disk image | |
# using the IdentifyLatestJDKRelease function. | |
IdentifyLatestJDKRelease | |
# Download the latest Oracle Java 10 JDK software disk image | |
# The curl -L option is needed because there is a redirect | |
# that the requested page has moved to a different location. | |
/usr/bin/curl –retry 3 -Lo "$java_ten_jdk_dmg" "$fileURL" -H "Cookie: oraclelicense=accept-securebackup-cookie" | |
# Specify a /tmp/java_ten_jdk.XXXX mountpoint for the disk image | |
TMPMOUNT=$(/usr/bin/mktemp -d /tmp/java_ten_jdk.XXXX) | |
# Mount the latest Oracle Java 10 disk image to /tmp/java_ten_jdk.XXXX mountpoint | |
hdiutil attach "$java_ten_jdk_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen | |
# Install Oracle Java 10 JDK from the installer package. This installer may | |
# be stored inside an install application on the disk image, or there | |
# may be an installer package available at the root of the mounted disk | |
# image. | |
if [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*JDK*\.pkg -o -iname \*JDK*\.mpkg \))" ]]; then | |
pkg_path="$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*JDK*\.pkg -o -iname \*JDK*\.mpkg \))" | |
elif [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \))" ]]; then | |
oracle_app=$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \)) | |
if [[ -e "$(/usr/bin/find "$oracle_app"/Contents/Resources -maxdepth 1 \( -iname \*JDK*\.pkg -o -iname \*JDK*\.mpkg \))" ]]; then | |
pkg_path="$(/usr/bin/find "$oracle_app"/Contents/Resources -maxdepth 1 \( -iname \*JDK*\.pkg -o -iname \*JDK*\.mpkg \))" | |
fi | |
fi | |
# Before installation, the installer's developer certificate is checked to | |
# see if it has been signed by Oracle's developer certificate. Once the | |
# certificate check has been passed, the package is then installed. | |
if [[ "${pkg_path}" != "" ]]; then | |
signature_check=`/usr/sbin/pkgutil –check-signature "$pkg_path" | awk /'Developer ID Installer/{ print $5 }'` | |
if [[ ${signature_check} = "Oracle" ]]; then | |
echo "The downloaded Oracle Java 10 JDK installer package is signed by Oracle's Developer ID Installer certificate." | |
echo "Proceeding with installation of the latest Oracle Java 10 JDK." | |
# Install Oracle Java 10 JDK from the installer package stored inside the disk image | |
/usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" | |
# Report on the currently installed version of the Oracle Java 10 JDK | |
javaJDKVersion=`/usr/bin/java -version 2>&1 | awk 'NR==1{ gsub(/"/,""); print $3 }'` | |
echo "Oracle Java 10 JDK $javaJDKVersion has been installed." | |
fi | |
fi | |
# Clean-up | |
# Unmount the Oracle Java 10 JDK disk image from /tmp/java_ten_jdk.XXXX | |
/usr/bin/hdiutil detach -force "$TMPMOUNT" | |
# Remove the /tmp/java_ten_jdk.XXXX mountpoint | |
/bin/rm -rf "$TMPMOUNT" | |
# Remove the downloaded disk image | |
/bin/rm -rf "$java_ten_jdk_dmg" | |
fi | |
exit "$error" |
Oracle Java 10 JRE script:
The script below will download a disk image containing the latest version of the Java 10 JRE from Oracle and install the JRE using the installer package stored inside the downloaded disk image.
How the script works:
- Verifies that the Mac is running a Java 10-compatible operating system
- Uses curl to download a disk image containing the latest Java 10 JRE installer from Oracle’s web site
- Renames the downloaded disk image to java_ten_jre.dmg and stores it in /tmp.
- Mounts the disk image silently in /tmp. The mounted disk image will not be visible to any logged-in user.
- Installs the latest Java 10 JRE using the installer package stored inside the disk image.
- After installation, unmounts the disk image and removes it from the Mac in question.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script downloads and installs the latest available Oracle Java 10 JRE CPU release or PSU release for compatible Macs | |
#Set error status | |
error=0 | |
# Determine OS version | |
osvers=$(sw_vers -productVersion | awk -F. '{print $2}') | |
IdentifyLatestJRERelease(){ | |
# Determine the download URL for the latest CPU release or PSU release. | |
Java_10_JRE_CPU_URL=$(/usr/bin/curl -s http://www.oracle.com/technetwork/java/javase/downloads/jre10-downloads-4417026.html | grep -ioE "http://download.oracle.com/otn-pub/java/jdk/.*?/jre-10.*?.dmg" | head -1) | |
Java_10_JRE_PSU_URL=$(/usr/bin/curl -s http://www.oracle.com/technetwork/java/javase/downloads/jre10-downloads-4417026.html | grep -ioE "http://download.oracle.com/otn-pub/java/jdk/.*?/jre-10.*?.dmg" | tail -1) | |
# Use the Version variable to determine if the script should install the latest CPU release or PSU release. | |
if [[ "$Version" = "PSU" ]] && [[ "$Java_10_JRE_PSU_URL" != "" ]]; then | |
fileURL="$Java_10_JRE_PSU_URL" | |
echo "Installing Oracle Java 10 JRE Patch Set Update (PSU) –" "$Java_10_JRE_PSU_URL" | |
elif [[ "$Version" = "PSU" ]] && [[ "$Java_10_JRE_PSU_URL" = "" ]]; then | |
echo "Unable to identify download URL for requested Oracle Java 10 JRE Patch Set Update (PSU). Exiting." | |
error=1 | |
exit "$error" | |
fi | |
if [[ "$Version" = "CPU" ]] && [[ "$Java_10_JRE_CPU_URL" != "" ]]; then | |
fileURL="$Java_10_JRE_CPU_URL" | |
echo "Installing Oracle Java 10 JRE Critical Patch Update (CPU) –" "$Java_10_JRE_PSU_URL" | |
elif [[ "$Version" = "CPU" ]] && [[ "$Java_10_JRE_CPU_URL" = "" ]]; then | |
echo "Unable to identify download URL for requested Oracle Java 10 JRE Critical Patch Update (CPU). Exiting." | |
error=1 | |
exit "$error" | |
fi | |
} | |
if [[ ${osvers} -lt 10 ]]; then | |
echo "Oracle Java 10 JRE is not available for Mac OS X 10.9.5 or earlier." | |
fi | |
if [[ ${osvers} -ge 10 ]]; then | |
# Specify name of downloaded disk image | |
java_ten_jre_dmg="/tmp/java_ten_jre.dmg" | |
# Use the Version variable to set if you want to download the latest CPU release or the latest PSU release. | |
# The difference between CPU and PSU releases is as follows: | |
# | |
# Critical Patch Update (CPU): contains both fixes to security vulnerabilities and critical bug fixes. | |
# | |
# Patch Set Update (PSU): contains all the fixes in the corresponding CPU, plus additional fixes to non-critical problems. | |
# | |
# For more details on the differences between CPU and PSU updates, please see the link below: | |
# | |
# http://www.oracle.com/technetwork/java/javase/cpu-psu-explained-2331472.html | |
# | |
# Setting the variable as shown below will set the script to install the CPU release: | |
# | |
# Version=CPU | |
# | |
# Setting the variable as shown below will set the script to install the PSU release: | |
# | |
# Version=PSU | |
# | |
# By default, the script is set to install the CPU release. | |
Version=CPU | |
# Identify the URL of the latest Oracle Java 10 JRE software disk image | |
# using the IdentifyLatestJRERelease function. | |
IdentifyLatestJRERelease | |
# Download the latest Oracle Java 10 JRE software disk image | |
# The curl -L option is needed because there is a redirect | |
# that the requested page has moved to a different location. | |
/usr/bin/curl –retry 3 -Lo "$java_ten_jre_dmg" "$fileURL" -H "Cookie: oraclelicense=accept-securebackup-cookie" | |
# Specify a /tmp/java_ten_jre.XXXX mountpoint for the disk image | |
TMPMOUNT="$(/usr/bin/mktemp -d /tmp/java_ten_jre.XXXX)" | |
# Mount the latest Oracle Java 10 disk image to /tmp/java_ten_jre.XXXX mountpoint | |
hdiutil attach "$java_ten_jre_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen | |
# Install Oracle Java 10 JRE from the installer package. This installer may | |
# be stored inside an install application on the disk image, or there | |
# may be an installer package available at the root of the mounted disk | |
# image. | |
if [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*Java*\.pkg -o -iname \*Java*\.mpkg \))" ]]; then | |
pkg_path="$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*Java*\.pkg -o -iname \*Java*\.mpkg \))" | |
elif [[ -e "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \))" ]]; then | |
oracle_app=$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.app \)) | |
if [[ -e "$(/usr/bin/find "$oracle_app"/Contents/Resources -maxdepth 1 \( -iname \*Java*\.pkg -o -iname \*Java*\.mpkg \))" ]]; then | |
pkg_path="$(/usr/bin/find "$oracle_app"/Contents/Resources -maxdepth 1 \( -iname \*Java*\.pkg -o -iname \*Java*\.mpkg \))" | |
fi | |
fi | |
# Before installation, the installer's developer certificate is checked to | |
# see if it has been signed by Oracle's developer certificate. Once the | |
# certificate check has been passed, the package is then installed. | |
if [[ "${pkg_path}" != "" ]]; then | |
signature_check=$(/usr/sbin/pkgutil –check-signature "$pkg_path" | awk /'Developer ID Installer/{ print $5 }') | |
if [[ ${signature_check} = "Oracle" ]]; then | |
echo "The downloaded Oracle Java 10 JRE installer package is signed by Oracle's Developer ID Installer certificate." | |
echo "Proceeding with installation of the latest Oracle Java 10 JRE." | |
# Install Oracle Java 10 JRE from the installer package stored inside the disk image | |
/usr/sbin/installer -dumplog -verbose -pkg "${pkg_path}" -target "/" | |
# Report on the currently installed version of the Oracle Java 10 JRE | |
javaJREVersion=$(/usr/bin/defaults read "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info" CFBundleVersion) | |
echo "Oracle Java 10 JRE $javaJREVersion has been installed." | |
fi | |
fi | |
# Clean-up | |
# Unmount the Oracle Java 10 JRE disk image from /tmp/java_ten_jre.XXXX | |
/usr/bin/hdiutil detach -force "$TMPMOUNT" | |
# Remove the /tmp/java_ten_jre.XXXX mountpoint | |
/bin/rm -rf "$TMPMOUNT" | |
# Remove the downloaded disk image | |
/bin/rm -rf "$java_ten_jre_dmg" | |
fi | |
exit "$error" |
Ths script not enabling the plugins for browser
404 for both on Github
JRE 10 is no longer available, Java 12 is only JDK (no JRE)
Now one wants to use: https://jdk.java.net/13/