0%

彻底卸载 .pkg 和 .mpkg 软件的方法

有时候我们安装一个软件,下载到的不是可以直接复制进 Application 目录的 .app 文件,而是 .pkg/.mpkg 安装包。这是类似于 Windows 下的 setup.exe 安装文件,其缺点是无法在 Application 中直接删除应用(.app 文件)来卸载。有一种解决方案是删除它的相关文件及文件夹来卸载它们,但这样的卸载工作繁琐且又不彻底。

因此我们需要一个 pkg 管理工具——pkg uninstaller

安装 pkg_uninstaller

安装它的方法很简单,只需要一条命令

1
bash < <(curl -sL https://raw.github.com/mpapis/pkg_uninstaller/master/pkg-install)

然后在 .bash_profile 里加入路径信息

1
export PATH = $PATH:/opt/pkg_uninstaller:$HOME/.pkg_uninstaller

最后再 source .bash_profile 即可。

使用 pkg uninstaller

  • pkg-list 列出所有电脑上的 pkg 软件
  • pkg-uninstall <PKG_NAME> 用于卸载单个 pkg 软件

配合 Shell 脚本批量卸载

例如我要卸载所有用 pkg 包安装的 ROOT 工具,

1
pkg-list | grep 'ROOT' >> temp.sh

得到

1
2
3
4
5
6
7
8
9
10
11
com.HEPSoft.ROOT.applications
com.HEPSoft.ROOT.c-index-test
com.HEPSoft.ROOT.clang-headers
com.HEPSoft.ROOT.clangAnalysis
com.HEPSoft.ROOT.clangAST
com.HEPSoft.ROOT.clangASTMatchers
com.HEPSoft.ROOT.clangBasic
com.HEPSoft.ROOT.clangCodeGen
com.HEPSoft.ROOT.clangDriver
com.HEPSoft.ROOT.clangDynamicASTMatchers
...

在 vim 中编辑 temp.sh 文件,利用 vim 命令

1
:%s/^/sudo\ pkg-uninstall\ /g

这是在每一行前加上 pkg-uninstall 命令,为防止权限不足,加上 sudo

然后回到 bash 执行 sh temp.sh 即可。当然,最后别忘了删除 temp.sh