Removing Oracle Java from macOS
2023-8-12 04:41:7 Author: derflounder.wordpress.com(查看原文) 阅读量:16 收藏

Home > Java, Mac administration, macOS, Scripting > Removing Oracle Java from macOS

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.

  • Old license: License costs were based on how many employees your company has which used Oracle’s Java.
  • Current license: License costs are based on how many employees your company has.

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:

  • JRE: /Library/Internet Plug-Ins
  • JDK: /Library/Java/JavaVirtualMachines

The script will check those directories for the following conditions:

  1. Is the directory in question empty? If yes, nothing to do and the script moves on.
  2. If the directory is not empty, it checks to see if there are JRE or JDKs installed.
  3. If there are JREs or JDKs installed, check if the JRE or JDK in question is from Oracle.
  4. If a JRE or JDK is from Oracle, remove the Oracle Java JRE or JDK installation.

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:

https://github.com/rtrouton/rtrouton_scripts/tree/main/rtrouton_scripts/uninstallers/oracle_java_uninstall


#!/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

文章来源: https://derflounder.wordpress.com/2023/08/11/removing-oracle-java-from-macos/
如有侵权请联系:admin#unsafe.sh