位元詩人 技術雜談:How to Remove PKG packages on Mac

Facebook Twitter LinkedIn LINE Skype EverNote GMail Yahoo Email

For GUI mac software, AppCleaner is an easy way to safely and cleanly uninstall it on Mac. However, there is no easy method to uninstall PKG packages on Mac.

I have written a small script to uninstall PKG packages on my homebin repo. You can easily download it with curl or wget.


$ curl https://raw.githubusercontent.com/cwchen123/homebin/master/removepkg > removepkg
$ chmod +x removepkg
$ mkdir /usr/local/bin
$ mv removepkg /usr/local/bin
{{< / highlight >}}

The script deletes only the files of a package first; then deletes only empty directories of the package.  Therefore, other directories will not be deleted mindlessly.

Use `pkgutil --pkgs` to see which packages to uninstall.  You may use `grep` to search the package.

```console
$ pkgutil --pkgs | grep package_name
{{< / highlight >}}

Before you really uninstall the package, you may look a while these files with `removepkg --dry`.  Say we want to remove Midnight Commander for Mac.

```console
$ removepkg --dry hu.louise.mc.midnightCommanderInstaller.usr.pkg
{{< / highlight >}}

If you are sure to remove the package, repeat the command with `sudo`.  With the same case:

```console
$ sudo removepkg hu.louise.mc.midnightCommanderInstaller.usr.pkg
{{< / highlight >}}
關於作者

身為資訊領域碩士,位元詩人 (ByteBard) 認為開發應用程式的目的是為社會帶來價值。如果在這個過程中該軟體能成為永續經營的項目,那就是開發者和使用者雙贏的局面。

位元詩人喜歡用開源技術來解決各式各樣的問題,但必要時對專有技術也不排斥。閒暇之餘,位元詩人將所學寫成文章,放在這個網站上和大家分享。