I have installed a .pkg package with the installer command. But there are problem with that installation. Now I want to remove it. Is there a standard way to do it with command line interface?

Note: I have no access to the GUI interface of the machine.

  • Do you want to share the pkg? They can be nested and have pre and post scripts. Those are not reversible in general.If you just want the hypothetical, I could flush this out into an answer that says no and here is why... – bmike Oct 3 '19 at 11:41
  • 1
    @bmike Well, you could list its contents with lsbom and delete those, but this won't reverse things done by the installation scripts. – bot47 Oct 3 '19 at 11:53
  • 1
    100% correct @maxreid - also, any packages that violate the “commandments” will fail in incomplete and/or bad and spectacular ways - see the recent google keystone deleting /var and zoom.us installing malware and security exploits as part of the preflight script, etc... – bmike Oct 3 '19 at 17:42
  • @bmike: I installed a newer version of git on an old mac. The binary doesn't work so I want to remove it. – Koala Yeung Oct 4 '19 at 2:47

You can use pkgUtil for it.

$ 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 the following:

I leave this up to you as modifying files with root user maybe a bit risky

$ 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 -o -n 1 -0 sudo rm -i

To remove directories as well as files, list the directories from the package using:

$ pkgutil --only-dirs --files the-package-name.pkg

The following command could be used to attempt removal of each directory, although be aware that when System Integrity Protection is active, there are some file paths that not even the root user may modify. Nevertheless — and needless to say — extreme care should always be taken when removing files with root privileges.

$ pkgutil --only-dirs --files the-package-name.pkg | tr '\n' '\0' | xargs -o -n 1 -0 sudo rm -ir

Once you’ve uninstalled the files, you can remove the receipt with:

$ sudo pkgutil --forget the-package-name.pkg

For more details, see the pkgutil main page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .