pkg-uninstall

Safely uninstall your OS X packages from the command line

Download .zip Download .tar.gz View on GitHub

OS X Package Uninstaller

by Benjamin Gandon © 2015

Overview

pkg-uninstall is a command line tool that helps in uninstalling OS X packages.

Several safe-guards are implemented in pkg-uninstall to ensure that the uninstallation process is somehow kept under control. But it will not prevent you from doing silly things like uninstalling core packages that are vital to your OS X system and applications.

This is inherent to OS X Packages. Thus, you are strongly advised to make a backup copy of your system prior to using pkg-uninstall. Go and setup Time Machine for that.

Usage

General usage form is:

pkg-uninstall [options] <package-id> ...

Where package identifiers are to be found in the list of installed packages, as returned by pkgutil --pkgs.

So you should first make a backup copy of your system. Then, you should dry run pkg-uninstall with standard user privileges and the --dry-run option:

pkg-uninstall --dry-run <package-id>

With this, you'll see what would happen, without actually changing anything to the system.

Once you're really sure of what you're doing, you might finally run:

sudo pkg-uninstall <package-id>

Options

Several options can be specified.

  • --help: display usage informationdisplay usage information.

  • --version: display version number.

  • --dry-run (highly recommended for a first use): Explain what would happen during the uninstallation, without actually modifying the system. When running the tool with this option, you don't need superuser privileges.

  • --verbose: be verbose about directories and files that are listed as part of the installed package, but that cannot be actually found in the file system.

  • --force: force uninstallation, even if some directories or some files are actually missing on the file system. This just bypasses safeguards that have the tool stop early in the process. It does not enforce any operations that are prevented by --dry-run.

  • --prefix-dir: specify one single installation prefix directory for all packages to uninstall, instead of fetching their individual InstallPrefixPath values that are stored in the receipts database. Package directories and files will have this directory prepended before tring to remove them from the file system. Both --prefix-dir=<dir> and --prefix-dir <dir> syntaxes are supported.

  • --infer-prefix-dir: for each package to uninstall, do not use the InstallPrefixPath value, but infer a suitable directory instead. This might take a long time to run. See below for more details.

Safeguards

  • Check that all specified packages are listed as installed before proceeding. Stop with failure message if one of them is not.

  • Check that the directories and files (that are listed as part of the packages) are actually present on the file system, taking any installation prefix directory into account. Report any issue about that (with details when --verbose). Advise the user to --force uninstallation to proceed any further.

Caveats

pkg-uninstall supports files and directories that include blanks like spaces and tabs. But it does not supports new line (LF) and double quotes (") charaters in filenames. If you run into such situation, then a rewrite in Perl (or any similar language) will be necessary to obtain the required robustness.

License

pkg-uninstall is released under the MIT License.