卸载了Command Line Tools 命令行工具后,出现软件更新提醒,如何解决

在新的Mac (Apple Silicon芯片,macOS 12.0 )上,安装了Command Line Tools 命令行工具,然后通过删除卸载它们, 仍然在“系统偏好设置”>软件更新中获取工具的更新。只是删除/Library/Developer/CommandLineTool不够的.

实际上,更新以文件的形式位于/Library/Apple/System/Library/Receipts里面,如下几个文件.

com.apple.pkg.CLTools_Executables.{bom,plist}

com.apple.pkg.CLTools_SDK_macOS*.{bom,plist}

com.apple.pkg.CLTools_macOS_SDK.{bom,plist}

它们受SIP保护:要删除它们,我必须首先禁用SIP(即禁用SIP,删除文件,重新启用SIP)



完美解决!!!


[经过版主编辑]

MacBook Pro Apple Silicon

发布日期 2022年7月4日 上午8:39

回复
问题被标记为 排名最靠前的回复

发布日期 2022年7月4日 下午8:55

综合子寒和你的两方面的描述,刚才经过尝试,可以使用下面的脚本来卸载。这个工作的前提是子寒所述的目录是正确的,而且在系统偏好的软件更新中,的确是使用这个目录来管理已安装程序包的。


步骤大体与子寒说的是一样的:

  1. 禁止 SIP
  2. 运行下面的一行命令
  3. 开启 SIP


命令是:

Vol="/Library/Apple/System"; if [ "$(csrutil status | awk -F': ' '{print $2}')" = "disabled." ]; then /usr/sbin/pkgutil --pkgs="com.apple.pkg.CLTools_.*" --volume "$Vol" | while read -r pkg; do /usr/sbin/pkgutil --forget "$pkg" --volume "$Vol"; done; else echo "After disbale SIP, run this command again, and then enable SIP."; fi


命令说明:命令有点长,其实它是由我刚才写的小脚本转化过来的,之所以做成一行命令,就是便于在终端中执行。


大概解释一下:

以前呢,尝试过使用 pkgutil,但是没有用。虽然说安装的时候是产生了 package installer 相关的记录,因为pkgutil --pkgs 的确是显示有CLTools的记录,但是删除时有错误,所以,当时猜测 "软件更新" 好像是自己另有一套。


如前面所说,pkgutil --pkgs 可以看到的确是安装了 com.apple.pkg.CLTools_*的各种包,但是直接进行 --forget 的话,却会出错

比如 sudo pkgutil --forget com.apple.pkg.CLTools_Executables

Unknown error Error Domain=NSCocoaErrorDomain Code=4 "“com.apple.pkg.CLTools_Executables.bom” couldn’t be removed." UserInfo={NSUserStringVariant=(
  Remove
), NSFilePath=/var/db/receipts/com.apple.pkg.CLTools_Executables.bom, NSUnderlyingError=0x600000576880 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}.
Forgot package 'com.apple.pkg.CLTools_Executables' on '/'.


进入 /var/db/receipts 目录,里面的确没有那些 .bom 或 .plist文件。所以猜测,在安装过程中,它的确是使用了 installer 的方法,但是他们的 plist 和 bom文件肯定被定向到了其他地方。


有了子寒的发现,就找到了它被移动的目标目录。那么就可以通过指定 Volume 的方式,既把包移除了,也从installer的数据库中移除了。于是就有了这个小命令行。

回复量: 8
问题被标记为 排名最靠前的回复

2022年7月4日 下午8:55 回应 Sariel

综合子寒和你的两方面的描述,刚才经过尝试,可以使用下面的脚本来卸载。这个工作的前提是子寒所述的目录是正确的,而且在系统偏好的软件更新中,的确是使用这个目录来管理已安装程序包的。


步骤大体与子寒说的是一样的:

  1. 禁止 SIP
  2. 运行下面的一行命令
  3. 开启 SIP


命令是:

Vol="/Library/Apple/System"; if [ "$(csrutil status | awk -F': ' '{print $2}')" = "disabled." ]; then /usr/sbin/pkgutil --pkgs="com.apple.pkg.CLTools_.*" --volume "$Vol" | while read -r pkg; do /usr/sbin/pkgutil --forget "$pkg" --volume "$Vol"; done; else echo "After disbale SIP, run this command again, and then enable SIP."; fi


命令说明:命令有点长,其实它是由我刚才写的小脚本转化过来的,之所以做成一行命令,就是便于在终端中执行。


大概解释一下:

以前呢,尝试过使用 pkgutil,但是没有用。虽然说安装的时候是产生了 package installer 相关的记录,因为pkgutil --pkgs 的确是显示有CLTools的记录,但是删除时有错误,所以,当时猜测 "软件更新" 好像是自己另有一套。


如前面所说,pkgutil --pkgs 可以看到的确是安装了 com.apple.pkg.CLTools_*的各种包,但是直接进行 --forget 的话,却会出错

比如 sudo pkgutil --forget com.apple.pkg.CLTools_Executables

Unknown error Error Domain=NSCocoaErrorDomain Code=4 "“com.apple.pkg.CLTools_Executables.bom” couldn’t be removed." UserInfo={NSUserStringVariant=(
  Remove
), NSFilePath=/var/db/receipts/com.apple.pkg.CLTools_Executables.bom, NSUnderlyingError=0x600000576880 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}.
Forgot package 'com.apple.pkg.CLTools_Executables' on '/'.


进入 /var/db/receipts 目录,里面的确没有那些 .bom 或 .plist文件。所以猜测,在安装过程中,它的确是使用了 installer 的方法,但是他们的 plist 和 bom文件肯定被定向到了其他地方。


有了子寒的发现,就找到了它被移动的目标目录。那么就可以通过指定 Volume 的方式,既把包移除了,也从installer的数据库中移除了。于是就有了这个小命令行。

2022年7月4日 上午9:42 回应 子寒_

如何关闭和开启sip

以mbp14 2021为例

关闭sip: 关机后,长按开机键不放,出现选项,进去输入登录密码,左上角打开终端,输入csrutil disable,输入γ,输入密码,等待一会,重启.

删除文件:重启进系统, 进/Library/Apple/System/Library/Receipts删除cltools系列文件(不要删除其他文件).

开启sip:关机后,长按开机键不放,出现选项,进去输入登录密码,左上角打开终端,输入csrutil enable,输入γ,输入密码,等待一会,重启.

进系统后重新进更新,已经没有提示了.

2022年7月6日 上午8:49 回应 李晓博

多谢反馈。

原因是,我测试的时候是转换到 root 之后执行的,所以目录中少了个提升权限的 sudo。


变更如下:

Vol="/Library/Apple/System"; if [ "$(csrutil status | awk -F': ' '{print $2}')" = "disabled." ]; then /usr/sbin/pkgutil --pkgs="com.apple.pkg.CLTools_.*" --volume "$Vol" | while read -r pkg; do sudo /usr/sbin/pkgutil --forget "$pkg" --volume "$Vol"; done; else echo "After disbale SIP, run this command again, and then enable SIP."; fi


运行时,当它提示输入密码的时候,输入当前管理员的密码,按回车键确认,注:输入过程中光标不会随着输入而移动。


2022年7月4日 下午10:24 回应 tonyfromcalgary

https://apple.stackexchange.com/questions/328034/removing-uninstalled-command-line-tools-from-appstore-updates

https://apple.stackexchange.com/questions/328101/pkgutil-forget-error-no-such-file-or-directory

根據這兩個帖子的總結來看, pkgutil雖然可以讀取到

/var/db/receipts, /System/Library/Receipts 和 /Library/Apple/System/Library/Receipts 的 bom 文件, 但是forget選項似乎是指定了/var/db/receipts作為prefix, 從時間跨度來看似乎是有意為之.

2022年7月6日 上午7:45 回应 tonyfromcalgary

使用了sudo 执行命令报错

lixiaobodeMacBook-Pro ~ % Vol="/Library/Apple/System"; if [ "$(csrutil status | awk -F': ' '{print $2}')" = "disabled." ]; then /usr/sbin/pkgutil --pkgs="com.apple.pkg.CLTools_.*" --volume "$Vol" | while read -r pkg; do /usr/sbin/pkgutil --forget "$pkg" --volume "$Vol"; done; else echo "After disbale SIP, run this command again, and then enable SIP."; fi


Unknown error Error Domain=NSCocoaErrorDomain Code=513 "“com.apple.pkg.CLTools_SDK_macOS12.bom” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=(

Remove

), NSFilePath=/Library/Apple/System/Library/Receipts/com.apple.pkg.CLTools_SDK_macOS12.bom, NSUnderlyingError=0x600003911ce0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}.

Forgot package 'com.apple.pkg.CLTools_SDK_macOS12' on '/Library/Apple/System'.

Unknown error Error Domain=NSCocoaErrorDomain Code=513 "“com.apple.pkg.CLTools_Executables.bom” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=(

Remove

), NSFilePath=/Library/Apple/System/Library/Receipts/com.apple.pkg.CLTools_Executables.bom, NSUnderlyingError=0x6000038b31e0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}.

Forgot package 'com.apple.pkg.CLTools_Executables' on '/Library/Apple/System'.

Unknown error Error Domain=NSCocoaErrorDomain Code=513 "“com.apple.pkg.CLTools_SDK_macOS110.bom” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=(

Remove

), NSFilePath=/Library/Apple/System/Library/Receipts/com.apple.pkg.CLTools_SDK_macOS110.bom, NSUnderlyingError=0x6000007fa520 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}.

Forgot package 'com.apple.pkg.CLTools_SDK_macOS110' on '/Library/Apple/System'.

Unknown error Error Domain=NSCocoaErrorDomain Code=513 "“com.apple.pkg.CLTools_SwiftBackDeploy.bom” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=(

Remove

), NSFilePath=/Library/Apple/System/Library/Receipts/com.apple.pkg.CLTools_SwiftBackDeploy.bom, NSUnderlyingError=0x6000008bf1e0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}.

Forgot package 'com.apple.pkg.CLTools_SwiftBackDeploy' on '/Library/Apple/System'.

Unknown error Error Domain=NSCocoaErrorDomain Code=513 "“com.apple.pkg.CLTools_macOS_SDK.bom” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=(

Remove

), NSFilePath=/Library/Apple/System/Library/Receipts/com.apple.pkg.CLTools_macOS_SDK.bom, NSUnderlyingError=0x600002c6b1e0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}.

Forgot package 'com.apple.pkg.CLTools_macOS_SDK' on '/Library/Apple/System'.

这个主题已被系统或社区团队关闭。 你可以为你认为有帮助的任何帖子投票,也可以在社区中搜索其他答案。

卸载了Command Line Tools 命令行工具后,出现软件更新提醒,如何解决

欢迎来到 Apple 支持社区
Apple 客户在其产品方面互相帮助的论坛。使用您的 Apple 帐户开始畅游其中吧!!