【教程】macOS完全卸載Java開發環境


✨適用情況

  • 下載Oracle官方的 dmg 后 雙擊 pkg文件形式安裝的Java環境
  • Homebrew 或者 MacPorts 安裝

如果通過 Homebrew 或者 MacPorts 安裝,也請按照如下方法卸載。


✨Standard Edition Installation Guide

Java Platform, Standard Edition Installation Guide 中對卸載都有詳細說明

JDK JRE分別都說明了卸載方式

卸載Java環境時要同時卸載JDK與JRE


官方文檔中特別強調

Note:
Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time that you perform an update of the OS.


各版本 Standard Edition Installation Guide 如下


✨卸載演示

Java8

根據上述提供的官方文檔卸載Java8

Java8


首先卸載JDK

查看當前JDK環境

cd /Library/Java/JavaVirtualMachines
ls

當前的JDK環境為 jdk1.8.0_281.jdk

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk

然后卸載JRE

To uninstall the JRE, you must have Administrator privileges and execute the remove commands either as root or by using the sudo(8) tool.

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefpane

與卸載前的設置界面對比可以注意到Java控制面板已經消失了。


Java17

根據上述提供的官方文檔卸載Java17


To uninstall the JDK on macOS:

You must have Administrator privileges.

Note:

Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time that you perform an update of the OS.

  1. Go to /Library/Java/JavaVirtualMachines.

  2. Remove the directory whose name matches the following format by executing the rm command as a root user or by using the sudo tool:

    /Library/Java/JavaVirtualMachines/jdk-17.interim.update.patch.jdk

    For example, to uninstall 17 Interim 0 Update 0 Patch 0:

    $ rm -rf jdk-17.jdk


cd /Library/Java/JavaVirtualMachines
ls

當前的JDK環境為 jdk-17.0.3.1.jdk

sudo rm -rf jdk-17.0.3.1.jdk

再次運行

java --version

卸載完成


✨參考及引用

https://stackoverflow.com/questions/50056598/how-to-uninstall-jdk-on-mac-os


⭐轉載請注明出處

本文作者:雙份濃縮馥芮白

原文鏈接:https://www.cnblogs.com/Flat-White/p/15823443.html

版權所有,如需轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM