How to Completely Uninstall JDK on macOS
- Details
- Written by Nam Ha Minh
- Last Updated on 29 April 2022   |   Print Email
When a JDK installation is no longer used, it should be completely removed from the computer. In this quick post, I’d like to share with you how to uninstall JDK entirely from macOS operating system.
1. Uninstall Oracle JDK on macOS
If you have a JDK installation that was installed by Oracle JDK installer, you need to find the JDK directory in the/Library/Java/JavaVirtualMachines path. Open a terminal window, change the current directory:
cd /Library/Java/JavaVirtualMachines
Then type ls command to see the installed JDK directories. You may find more than one JDK. Then type the following command to remove a JDK installation completely from macOS:
sudo rm -rf jdk-version
This command will be executed under root privilege (password required) - the specified JDK directory will be deleted recursively and forcefully.
If you uninstall JDK 1.8, you also need to remove 2 other directories using the following commands:
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefpane
Then you’re all done.
2. Uninstall OpenJDK on macOS
If you have OpenJDK installation, it’s very likely that it was extracted from an archive file to a specific directory. Open a terminal window, and type which java to see all locations pointing to the java program - it gives you some clues about where the JDK installation directory is.
The simply type the following command to completely uninstall OpenJDK from macOS:
rm -rf Path/To/OpenJDK
If you got permission denied error, use sudo prefix to run the command under root privilege.
Also consider update system environment variables such as JAVA_HOME and PATH, so it points to the currently installed JDK - not the one has been removed.
That’s my guide about how to completely uninstall JDK on macOS. To see the steps in action, watch the following video:
Related Articles:
- How to set JAVA_HOME in macOS and Linux permanently
- How to set JAVA_HOME environment variable on Windows 10
- What are JVM, JRE and JDK
- How to write, compile and run a hello world Java program for beginners
- Java Core Language Tutorials
Comments
Couldn't get rid of OpenJdk. Now I did, thanks