https://wincent.com/wiki/Uninstalling_packages_(.pkg_files)_on_Mac_OS_X describes how to uninstall .pkg using native pkgutil
.
Modified excerpt
$ pkgutil --pkgs # list all installed packages
$ pkgutil --files the-package-name.pkg # list installed files
After visually inspecting the list of files you can do something like:
$ pkgutil --pkg-info the-package-name.pkg # check the location
$ cd / # assuming the package is rooted at /...
$ pkgutil --only-files --files the-package-name.pkg | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f
$ pkgutil --only-dirs --files the-package-name.pkg | tail -r | tr '\n' '\0' | xargs -n 1 -0 sudo rmdir
Needless to say, extreme care should always be taken when removing files with root privileges. Particularly, be aware that some packages may update shared system components, so uninstalling them can actually break your system by removing a necessary component.
For smaller packages it is probably safer to just manually remove the files after visually inspecting the package file listing.
Apparently, there was once an --unlink
option available in pkgutil
, but as of Lion it is not mentioned in the man page. Perhaps it was removed because it was deemed too dangerous.
Once you've uninstalled the files, you can remove the receipt with:
$ sudo pkgutil --forget the-package-name.pkg
1I'd recommend using
rmdir
instead ofrm -r
; one could also usetac
ortail -r
to reverse the list of directory names so that they get deleted in the correct order – Sam Mason – 2014-10-13T13:43:36.87318DON'T RUN THE sudo rm -ir PART. The list includes the parent directories! So if the pkg installed something in /usr/... you will remove ALL /usr/ – FiloSottile – 2014-11-16T16:56:21.727
2I have changed the command for deleting directories to use
rmdir
(which does not delete not-empty-directories) and usestail -r
to list them in better order. – brablc – 2014-11-17T18:11:22.2171ironically, when using pgkutil I found an uninstaller.pl tucked away that I could use. Perfect! – cmroanirgo – 2015-02-13T02:26:54.793
One thing that pkgs don't seem to keep track of is the symlinks created by the pkgs. It's possible that cleaning up the package from the instructions above (or any of the methods here) will leave broken symlinks behind. – James McMahon – 2016-11-25T22:27:17.673