Home > Java, Mac administration, macOS, Scripting > Removing Oracle Java from macOS
As of January 23, 2023, Oracle made a change to how they’ve licensed Oracle’s Java (which is a separate license from the ones used for open source Java distributions like OpenJDK.) The new license terms are described here in Oracle’s FAQ, but to summarize the main difference between the old licensing and the current licensing is that Oracle introduced a new employee-based metric.
See the difference? Previously, if your company had 1000 employees and 2 used Oracle’s Java for purposes which required payment under the old license, the company paid for 2 licenses. In the current license, if your company has 1000 employees and 2 use Oracle’s Java, Oracle may say that now the company needs to pay for 1000 licenses.
There’s more to it and I am not the person to turn to when needing explanation of complex legal and financial questions, but the operational consequence for Mac admins is that companies which had previously been OK with Oracle Java being installed on their Macs may now be coming to their Mac admins, asking how Oracle Java can be removed and kept off.
To assist with this, I’ve written a script which should remove Oracle Java JREs and JDKs on macOS. For more details, please see below the jump.
The script will check the following directories for Oracle Java JREs and JDKs:
The script will check those directories for the following conditions:
This script should leave all non-Oracle Java installs that you may have on the Mac intact and untouched. However, I strongly recommend testing in your own environment before any deployment to make sure it is not removing anything you don’t want to have removed.
The script is available below and also from GitHub at the following location:
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 | |
# Checks for Oracle Java JRE and JDK installs and removes all | |
# identified installations. | |
installedJREs="/Library/Internet Plug-Ins" | |
installedJDKs="/Library/Java/JavaVirtualMachines" | |
# Check to see if /Library/Internet Plug-Ins is empty. | |
if [[ -n $(ls -A "$installedJREs") ]]; then | |
# If it's not empty, check for installed JREs. If an installed JRE | |
# is detected, check to see if it's from Oracle. | |
if [[ -x "${installedJREs}/JavaAppletPlugin.plugin" ]]; then | |
jreVendor=$(/usr/bin/defaults read "${installedJREs}/JavaAppletPlugin.plugin/Contents/Enabled.plist" CFBundleIdentifier | /usr/bin/grep -Eo "oracle") | |
# If it's from Oracle, remove the Java installation. | |
if [[ "$jreVendor" = "oracle" ]]; then | |
rm -rf "${installedJREs}/JavaAppletPlugin.plugin" | |
fi | |
fi | |
fi | |
# Check to see if /Library/Java/JavaVirtualMachines is empty. | |
if [[ -n $(ls -A "$installedJDKs") ]]; then | |
# If it's not empty, check for installed JDKs. | |
for aJDKPath in ${installedJDKs}/*; do | |
# If an installed JDK is detected, check to see if it's from Oracle | |
jdkVendor=$(/usr/bin/defaults read "${aJDKPath}/Contents/Info.plist" CFBundleIdentifier | /usr/bin/grep -Eo "oracle") | |
# If it's from Oracle, remove the Java installation. | |
if [[ "$jdkVendor" = "oracle" ]]; then | |
rm -rf "${aJDKPath}" | |
fi | |
done | |
fi | |
exit 0 |