Skip to main content

Uninstall a pkg-Installed Mac App Completely Using Its pkgutil Receipt

No uninstall for a Mac .pkg? Read its pkgutil receipt, stop launchd services, move the app's files to a holding folder and forget the receipt, with rollback.

KBY Technologies13 min readTier L115 min
Uninstall a pkg-Installed Mac App Completely Using Its pkgutil Receipt

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

has no uninstall command for installer packages. To remove a pkg-installed Mac app completely, read its receipt with pkgutil --pkg-info and pkgutil --files, find the launch daemons and login items it registered, stop those services with launchctl bootout, move the files it owns into a root-only holding folder instead of deleting them, and only then discard the receipt with pkgutil --forget. The key constraint: the receipt only records what the package payload installed. Anything the app or its postinstall script created later is not in it, and pkgutil --forget deletes nothing on disk.

This playbook is for the Mac administrator who has to take a third-party agent, driver or app off managed Macs when the vendor ships no uninstaller, or when the uninstaller leaves pieces behind.

#How removals are usually handled today

Apple’s own advice for an app that isn’t Apple’s is to look for an Uninstall or Uninstaller app next to it, because that is the best way to delete the app together with its login items, extensions and data stored elsewhere. Failing that, drag the app to the Trash. On a single Mac that is fine. On a managed fleet it falls apart in three places.

First, dragging the app bundle away leaves its helper tools, launch daemons and preference files behind, and a daemon whose property list is still in place points at an executable that no longer exists. Second, the installer receipt stays, so the Mac still reports the package as installed and a later reinstall of the same version may not lay the files down again. Third, MDM tools often can’t help: Microsoft documents that an unmanaged macOS PKG app in Intune has no Uninstall assignment type, and that such an app is not removed from the Mac when the device is retired. The fallback is a hand-written removal script per vendor, and one built on rm -rf has no way back if it takes the wrong path.

#A better way is to let the receipt drive the removal

The installer keeps a receipt database, and pkgutil is the supported way to read it. Apple’s manual page is explicit that the files and folders where receipts are stored are subject to change, so never read or edit them directly. From the receipt you get the package’s version, volume and install location, and the list of every path its payload placed. You then add what the receipt can’t see, stop any services, move the files somewhere recoverable, and forget the receipt last.

Moving rather than deleting is the important design choice. A move within the same volume keeps ownership and permissions and can be reversed with another move. You delete the holding folder only after a quiet period in which nobody reports a broken workflow. If the app later turns out to be needed, the rollback is to put the files back, not to repackage anything.

Rendering diagram...

The diagram shows the order. The vendor’s uninstaller still comes first when one exists; the receipt steps then confirm it really removed everything and clean up the record it may have left.

#Step by step on a test Mac

Run this on a test Mac that has the same version of the app as the fleet before you script it. Each step says what you should see and when to stop.

  1. Find the package identifier. Run pkgutil --pkgs='com.example.*', using the vendor’s reverse prefix. The equals sign is required; without it the search string is ignored and every installed package ID is printed. Quote the pattern so the shell doesn’t expand it. Vendors often split one product across several packages, so expect more than one line. Stop if nothing matches: the app was not installed from a package, and this method doesn’t apply.

  2. Read the receipt. Run pkgutil --pkg-info com.example.app. It prints package-id, version, volume, location and install-time. Note the volume and location: the paths that pkgutil --files prints are relative to the package’s install location, which is usually, but not always, the root of the volume. An empty location means paths start at the volume root.

  3. List what the payload installed. Run pkgutil --files com.example.app. You will see shared parent folders as well as the package’s own items, for example usr, usr/local, usr/local/bin and then usr/local/bin/tool. Add --only-files or --only-dirs to split them. From this list, pick only the top-level items that belong to the product: its app bundle, its helper tools, its launchd property lists. Never pick a parent folder such as Applications, Library or usr/local/bin.

  4. Check each item really belongs to this package alone. Run pkgutil --file-info on each path you picked. It prints the pkgid that installed it, and if several packages placed the same file you get a list. If another package ID appears, leave the item where it is. If no package information appears at all, the file was copied, moved or created by a script rather than the payload.

  5. Find what the receipt can’t see. An app or tool might create daemons, agents, preferences and configuration files that were never part of the payload and are not tracked in the receipt. Run sudo sfltool dumpbtm, which Apple documents as printing the current status of login and background items, and look for entries from the vendor. On macOS 13 or later, System Settings > General > Login Items also lists items registered through Apple’s background task framework. For a daemon, sudo launchctl print system/com.example.helper shows where its definition came from on disk and its current state. Add anything you find to your list, and check it with pkgutil --file-info the same way.

  6. Run the vendor’s uninstaller if there is one. Then repeat steps 2 to 5. Whatever is still listed is what the uninstaller left behind.

  7. Stop the services. Daemons and agents have to be unloaded and quit before their files go, as Armin Briegel’s guide to inspecting packages on Scripting OS X points out. Quit the app, then for each system daemon run sudo launchctl bootout system/com.example.helper. For a per-user agent the domain target is gui/<uid>, for example gui/501/com.example.agent. Stop condition: if bootout reports an error for a service you expected to be loaded, don’t move its files yet; find out what is holding it.

  8. Move the files to a holding folder. The script below is a dry run until you set APPLY=1. It refuses any item another package also owns and recreates each item’s path under a root-only folder, so every move can be reversed exactly.

  9. Keep a copy of the receipt, then forget it. Run pkgutil --export-plist com.example.app > ~/com.example.app-receipt.plist to keep the full receipt record, then sudo pkgutil --forget com.example.app. This discards the receipt data and doesn’t touch installed files, which is why it comes last. Apple warns against using --forget from inside an installer script to paper over a broken package design; here it is used on its own, after the files have gone.

Following along? Tap a step’s number to tick it off.

1#!/bin/zsh
2# Dry run by default: prints what it would move. Set APPLY=1 to move.
3PKGID="com.example.app"
4BASE="/"          # volume plus location from pkgutil --pkg-info
5HOLD="/private/var/uninstall-holding/${PKGID}-$(date +%Y%m%d)"
6APPLY=0
7ITEMS=(
8  "Applications/Example.app"
9  "Library/LaunchDaemons/com.example.helper.plist"
10  "Library/PrivilegedHelperTools/com.example.helper"
11)
12(( APPLY )) && mkdir -m 700 -p "$HOLD"
13for rel in "${ITEMS[@]}"; do
14  src="${BASE%/}/$rel"
15  [[ -e "$src" ]] || { echo "not present: $src"; continue; }
16  owners=$(pkgutil --file-info "$src" | awk '/^pkgid:/{print $2}' | sort -u)
17  if [[ -n "$owners" && "$owners" != "$PKGID" ]]; then
18    echo "SKIP, also owned by: $owners  $src"; continue
19  fi
20  echo "move: $src -> $HOLD/$rel  (receipt: ${owners:-none})"
21  if (( APPLY )); then
22    mkdir -p "$HOLD/${rel:h}" && mv "$src" "$HOLD/$rel"
23  fi
24done

Run the script with sudo from your MDM’s script runner only after it has passed on a test Mac in dry-run mode. If a daemon is defined in /Library/LaunchDaemons, the article on running a root script at boot with a macOS LaunchDaemon explains the plist layout and the bootstrap and bootout domain targets in more detail.

A stylish MacBook Pro laptop showcasing macOS Sierra, highlighting modern technology and design.
Photo by John (Giannis) Tekeridis on Pexels

#Who can run the removal

Every step that changes state needs root, because the installer laid the files down as root. Keep that power narrow:

  • Only the MDM’s script runner, or an administrator on a test Mac, runs the move and forget steps. Users with local admin rights shouldn’t get a self-service button for it.
  • Each script names one package ID and an explicit list of items. A script that removes everything pkgutil --files prints is not acceptable, because that list includes shared system folders.
  • The holding folder is created with mode 700 under /private/var, so only root can read the moved files. Moved helper tools and daemons are still the vendor’s signed code; keeping them out of reach of standard users matters.
  • If the product is a security agent, endpoint protection or anything with a system extension, stop and use the vendor’s documented removal process. Removing those by hand can leave a Mac unprotected or in a state the vendor won’t support.

#Verify the Mac is clean

Check the result from the same read-only commands you started with:

  • pkgutil --pkgs='com.example.*' no longer lists the package ID you forgot.
  • pkgutil --file-info on the old app path reports only the path and volume, with no pkgid, or the path no longer exists.
  • sudo launchctl print system/com.example.helper no longer finds the service.
  • sudo sfltool dumpbtm no longer lists the vendor’s background items, and they are gone from System Settings > General > Login Items.
  • The holding folder contains every item the dry run listed, at the same relative paths.

Collect these as the script’s output in your MDM, so each Mac’s result is recorded rather than assumed.

#What goes wrong with receipt-based removals

The most damaging mistake is treating the --files list as a delete list. It contains directories such as Applications and usr/local, and a reverse-order rm -rf over it can remove folders other software depends on. Pick top-level items by hand, once, and put them in the script.

The second is ignoring the install location. If --pkg-info shows a location other than the volume root, every relative path has to be joined to it. Getting this wrong means the script finds nothing, or worse, finds something else at the same relative path.

Third, files created after install aren’t in the receipt. Caches, preferences in each user’s Library and items written by a postinstall script won’t appear in --files. That is why sfltool dumpbtm and the vendor’s own documentation matter. Per-user data in home folders is the user’s; leave it unless the vendor says otherwise.

Fourth, forgetting the receipt first. If you run --forget before moving the files, you lose the list that tells you what to move. If you move the files and never forget the receipt, the Mac still claims the package is installed, and reinstalling the same version may not put the files back. The receipt should be forgotten once the removal works, so a future reinstallation runs as a fresh install.

Finally, an app that is running or has a daemon still loaded. Moving the bundle of a running app or a loaded daemon’s binary leaves a process with nothing on disk, and launchd may keep trying to start it. The playbook on update failures caused by apps that are still in use covers detecting a running app before you touch its bundle.

Detailed close-up of a MacBook Pro keyboard showing the keys and backlight.
Photo by Moritz Kindler on Pexels

#Roll back a removal

Because nothing was deleted, rollback is the removal in reverse

  1. Move each item from /private/var/uninstall-holding/<package>-<date>/ back to the same relative path under the install base. A move on the same volume keeps ownership and permissions.
  2. Load each daemon again with sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.helper.plist, and confirm it with launchctl print.
  3. Reinstall the same signed package version, which writes a fresh receipt. Once a receipt has been forgotten, the installer treats the package as a new installation, so the payload is laid down again. Keep the receipt plist you exported to compare versions.
  4. Check that the app opens and that its login items reappear. If they need approval again, the playbook on automating background task approval shows how to approve them through a profile instead of the user.

Once the holding period is over and no rollback has been needed, deleting the holding folder is the only irreversible step. Make it a separate, deliberate decision rather than part of the removal script.

#What to track

Measure the removal by what the Macs report, not by how many scripts ran. Useful counts from your MDM’s inventory or script output:

  • Macs where pkgutil --pkgs still returns the package ID after the removal ran.
  • Macs where the dry run skipped an item because another package owns it. Each one needs a decision before the next run.
  • Macs where sfltool dumpbtm still shows the vendor’s background items.
  • Rollbacks requested during the holding period, and why.

Review those numbers when each removal wave finishes, and again before the holding folders are deleted. A second pass that finds no leftovers is the sign the item list is complete.

#Before you roll it out to the fleet

  • The vendor’s uninstaller, if any, has been run on a test Mac and its leftovers listed.
  • The package IDs, install base and top-level items are written into the script by hand.
  • Every item passed the pkgutil --file-info ownership check.
  • Launch daemons and agents are booted out before their files move.
  • The dry run output matches what you expect on at least one test Mac.
  • The receipt is exported before it is forgotten.
  • Rollback has been tested once: files moved back, services bootstrapped, package reinstalled.
  • Security agents and system extensions are excluded and handled through the vendor’s process.
  • The holding period is agreed, and deleting the holding folders is scheduled as its own change.

If the app was deployed by your MDM and is still assigned, remove the assignment first, or the next check-in may install it again. For an app that reports as installed but is missing after deployment, the reverse problem, see why a pkg shows success in MDM but the app is missing.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Reader Interaction

Comments

Add a thoughtful note on Uninstall a pkg-Installed Mac App Completely Using Its pkgutil Receipt. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Operate smarter, with fewer recurring tickets.

Receive new operational playbooks, incident-prevention guidance, automation scripts and recovery runbooks.