Removing Versions of Java on Mac OS
Sometimes multiple versions of Java being installed can contribute to issues with Java applications. An important step in fixing an issue such as this is uninstallation of older Java versions.
Java is installed to the following locations on Mac OS (folders within the /Library folder structure will require use of ‘sudo’ in the Terminal in order to allow removal):
/Library/Java/JavaVirtualMachines/
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/
/Library/PreferencePanes/JavaControlPanel.prefPane/
~/Library/Application\ Support/Oracle/Java/
Note
Please proceed with caution as the following commands remove files and folders from system areas of Mac OS. For a bit of additional safety, the commands presented here are wrapped in an if statement to ensure the specific folder(s) exist prior to deletion.
The following document is an example of the procedure to remove these files and folders, actual steps may differ as Java files can exist in multiple areas.
Check whether the JavaVirtualMachines folder exists
ls -d1 /Library/Java/JavaVirtualMachines/*
Note
If you receive an error message indicating ‘No such file or directory’, continue to the JavaAppletPlugin.plugin step.
Removing JavaVirtualMachine subfolders
Run the following command for each of the folders returned from the above.
Important
Substitute the proper folder name(s) in both portions of the example below:
if [[ -d /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/ ]]; then \
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/; fi
The above is just an example, substitute each of the folder names returned from the previous command. Mac OS will prompt for an administrative user password.
Removal of the JavaAppletPlugin.plugin location
Proceed with removing the JavaAppletPlugin.plugin location:
if [[ -d /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin ]]; then \
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/; fi
Mac OS will prompt for an administrative user password.
Removal of the JavaAppletPlugin.prefPane symlink
There may also be a symlink in place of the above folder:
if [[ -L /Library/PreferencePanes/JavaControlPanel.prefPane ]]; then \
sudo unlink /Library/PreferencePanes/JavaControlPanel.prefPane; fi
Mac OS will prompt for an administrative user password.
Removal of the Oracle Application Support Folder
Proceed with removing the Application Support/Oracle/Java folder:
if [[ -d ~/Library/Application\ Support/Oracle/Java/ ]]; then \
rm -rf ~/Library/Application\ Support/Oracle/Java/; fi
Confirming success of the Uninstall process
Upon uninstallation, the java -version
command should report the following:
Important
Do not follow the instructions indicated regarding navigating to Java.com as the CSE Department recommends AdoptOpenJDK rather than any Java.com or Oracle versions of Java.
Next steps and (re)installing Java
Proceed with reinstallation of an appropriate Java build by following the steps in the ‘Installing Java on Mac’ document.