How to Remove PKG packages on Mac

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 > removepkg
$ chmod +x removepkg
$ mkdir /usr/local/bin
$ mv removepkg /usr/local/bin

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.

$ pkgutil --pkgs | grep package_name

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.

$ removepkg --dry

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

$ sudo removepkg
上篇Convert TXT to Excel with Perl
下篇Install Ruby Gems in Home Directory