β

macOS卸载JDK

李阳的技术博客 24 阅读

一、使用pkgutil

使用如下命令即可查看使用Pkg安装的JDK信息:

pkgutil --pkgs |grep jdk
com.oracle.jdk-9.0.4
com.oracle.jdk8u161
com.oracle.jdk8u102
com.oracle.jdk7u79
com.oracle.jdk-10
com.oracle.jdk8u131
com.oracle.jdk-9

二、查看关联文件

进入/private/var/db/receipts目录查看pkg文件的关联信息

cd /private/var/db/receipts
ls *.jdk*.bom

com.oracle.jdk-10.bom    com.oracle.jdk7u79.bom
com.oracle.jdk-9.0.4.bom com.oracle.jdk8u161.bom

三、删除JDK目录

进入 /Library/Java/JavaVirtualMachines 路径,删除要删除的JDK版本的目录

cd /Library/Java/JavaVirtualMachines

ls 

jdk-10.jdk       jdk-9.0.4.jdk    jdk1.7.0_79.jdk  jdk1.8.0_161.jdk
sudo rm -fr jdk1.7.0_79.jdk

接着根据第二步执行命令的结果,执行如下命令:

lsbom -fls com.oracle.jdk8u91.bom|(cd /; sudo xargs rm)

此命令会提示大量的 No such file or directory 例如:

rm: ./Contents/Home/man/ja_JP.UTF-8/man1/schemagen.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/serialver.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/servertool.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/tnameserv.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/unpack200.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/wsgen.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/wsimport.1: No such file or directory
rm: ./Contents/Home/man/ja_JP.UTF-8/man1/xjc.1: No such file or directory

也可以不执行。

然后执行如下命令让系统彻底删除该信息

sudo pkgutil --forget com.oracle.jdk7u79

当然,如果本地只安装了一个JDK,那么还需要删除如下路径:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
作者:李阳的技术博客
专注于分享IT技术
原文地址:macOS卸载JDK, 感谢原作者分享。

发表评论