Skip to main content

Install a Mac Package With Declarative Management and Remove Its Files When Unassigned

Set UninstallBehavior Remove to true before the first install so macOS 27 removes a declarative package's files when you remove the configuration.

KBY Technologies9 min readTier L115 min
Install a Mac Package With Declarative Management and Remove Its Files When Unassigned

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

On a supervised Mac running 26 or later, a device management service can install a .pkg with a declarative package configuration, com.apple.configuration.package. On macOS 27, add an UninstallBehavior dictionary with Remove set to true before the package first installs, and the Mac deletes the files that package laid down when you remove the configuration. Set it after the install and nothing is tracked, so nothing is removed.

That ordering is the whole trap. The steps below build the package, write the manifest, set the configuration and prove the removal on a pilot Mac. They were checked against Apple’s documentation and its published declaration definitions on 28 November 2026.

#How removal is usually handled today

Many teams push packages with the InstallEnterpriseApplication command, which Apple says works on any managed Mac. Apple’s package guidance says a package can hold several apps and other content installed outside /Applications. An app bundle stored in /Applications can become managed and be removed on its own with the remove application command.

Apple describes no equivalent for the rest of the package’s content, so it stays on the disk unless you remove it yourself. Teams cover the gap with an uninstall script, or by reading the installer receipt, as in our walkthrough on uninstalling a pkg-installed Mac app using its pkgutil receipt. Both work, but each is a script someone has to write per package and keep current.

#What to do instead of cleaning up by script

Let the Mac keep the list. With the declarative package configuration the device records the files and directories the package creates or updates at install time, and removes them when the configuration is removed. Apple says the device also removes a package when the configuration is deactivated or the Mac unenrols.

The configuration has three keys that matter here. ManifestURL is required and points at the manifest the Mac downloads. InstallBehavior holds Install, set to Required or Optional; Optional is the default, and it leaves the install for the user to start from a management app. UninstallBehavior holds Remove, which defaults to false and which Apple lists as new in macOS 27.

Loading diagram...

Two limits shape the design. Apple says packages install only on supervised Macs in the system scope, which is the device channel of the service. And when a package contains an app, the app is not managed automatically. Manage it with an app configuration that carries an AppComposedIdentifier, which takes over only if the app’s code signature matches.

#How to build, install and remove the package, step by step

Do this on a pilot Mac that is supervised, enrolled in your service and running macOS 27. Keep a second pilot on macOS 26 for the comparison in the checking section.

  1. Build a signed package from the app: sudo pkgbuild --component <APP> --install-location /Applications --sign <CERT> /tmp/MyPackage.pkg. Apple says to set the install location to /Applications because the device manages apps only there. Sign the package, not the app, because Gatekeeper does not check apps installed through device management.

  2. Confirm the signature is valid and trusted with pkgutil --check-signature /tmp/MyPackage.pkg. Apple says the device installs only signed packages whose signature it can verify, so a package that is unsigned or untrusted shows up at this step, before any Mac sees it.

  3. List what the package will write with pkgutil --payload-files /tmp/MyPackage.pkg. Read the list. Everything in it is a candidate for deletion later, and a path shared with other software is a reason to stop.

  4. Get the hash for the manifest: shasum -a 256 /tmp/MyPackage.pkg.

  5. Write the manifest property list. In items/assets set kind to software-package, url to where the Mac downloads the package, and sha256 to the hash. For a large package Apple lets you give sha256s with a sha256-size instead. In items/metadata set a unique bundle-identifier, a bundle-version, kind set to software, and a title.

  6. Create the package configuration. Set ManifestURL to the manifest, InstallBehavior to Required for the pilot, and UninstallBehavior to Remove set to true. Assign it to the pilot Mac only, and only now: the setting must already be true at the first install.

  7. Watch the package status item, package.list, until the package state reads installed. Apple lists the other states as optional, queued, prompting-for-consent, downloading, installing and failed. A failed state carries a reasons array.

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

Your service’s console may name these keys differently or hide some of them. The values above are what the Mac receives, so check what your service actually sends before assuming a console toggle maps to Remove.

A detailed view of a MacBook Air with a focus on the keyboard and screen displaying app icons.
Photo by Guilherme Pedrosa on Pexels

#Who can change the removal setting

Treat Remove as a release decision, not a preference. Once a package is installed, flipping it from false to true changes nothing on that Mac, so a wrong choice at release time is fixed by a new install, not an edit. Keep the configuration in a change process with a named approver, and review it whenever a package changes what it ships.

Keep the scope narrow. Apple lists the configuration for supervised Macs and the system scope only. Sign every package with a certificate the Macs can verify, and keep the signing key with the people who release software rather than with the people who assign it.

Read the file list before you set Remove to true. Apple says the Mac tracks files the package creates or updates, and removes the files and directories it tracks. A package that overwrites a shared configuration file may therefore take that file with it when it goes. Apple does not describe this case, so treat it as a risk to test, not a documented behaviour.

#Checking it worked on a pilot Mac

First prove the install. When the status item reports installed, confirm the app and any files outside /Applications from your payload list are on the disk. If the state is failed, read reasons before anything else. Our guide to an MDM pkg that shows success while the app is missing covers the neighbouring case where a command reports success and nothing arrives.

Then prove the removal. Remove the configuration from the pilot Mac and wait for the status item to show the package as removed, which Apple reports with _removed set to true. Check that the files from your payload list are gone, and that anything a post-install script created is still there. Apple says changes made by post-install scripts, or later by users, are not tracked, so that second check is the one that shows you the limit.

Last, run the same release on the macOS 26 pilot. Apple lists UninstallBehavior as new in macOS 27, so do not expect macOS 26 Macs to remove files. Confirm what they do before you assign the configuration to a mixed fleet.

#What goes wrong

  • Setting Remove to true on a configuration that is already installed, then wondering why nothing is removed. Apple says the Mac cannot build the file list afterwards.
  • Expecting post-install script work to be undone. Files and settings a script creates are not tracked.
  • Leaving an old InstallEnterpriseApplication assignment in place. Apple says declarative management takes precedence and makes an install command for the same package fail.
  • Assuming the app inside the package is managed. It is not until an app configuration takes it over.
  • Pushing an update by changing only the package. Apple says the Mac does not update packages by itself: change bundle-version in the manifest and the configuration’s ServerToken.
  • Shipping a package that is signed with a certificate the Mac cannot verify, which Apple says the device will not install.
Detailed close-up of a MacBook Pro keyboard showing the keys and backlight.
Photo by Moritz Kindler on Pexels

#Backing out and recovering

The clean way back is the same action as the removal: remove the package configuration from the affected Macs. With Remove set to true at install time, the Mac deletes the files it recorded. With it set to false or absent, Apple says it removes only the system metadata for the package, so the files stay and you need the receipt-based cleanup from earlier.

Contain a bad release first. Stop assigning the configuration to new groups first, then remove it from the Macs that took it. If the package is a faulty update, Apple documents only the forward path, which is a new bundle-version and a new ServerToken. Test a move back to an older package on the pilot before you rely on it.

Anything the package changed outside its own payload needs its own rollback, because it is not tracked. Write that rollback before release, and keep the package, its manifest and its payload list together so a failed rollout can be reproduced. Before you trust the signature on a new build, our check for whether a Mac app or pkg is Developer ID signed and notarized is a useful second pass.

#What to track after rollout

Count packages that stay in failed or queued past the time you expect, per release, from the status item. Count the files left behind after a removal on your pilot Macs, using the payload list as the baseline. That number should be zero for tracked files and should name the script-created files you accept.

Watch the tickets that used to follow a removal, such as leftover helpers or stale files. Record the monthly count, and do not quote a percentage until you have a count from before the change.

#Before you roll it out beyond the pilot

  • The package is signed and pkgutil --check-signature reports it valid and trusted.
  • You have read the pkgutil --payload-files list and found no shared paths.
  • The manifest has a unique bundle-identifier, a bundle-version and the right sha256.
  • Remove is true in the first configuration that reaches any Mac.
  • The pilot install reached installed and the removal cleared the payload files.
  • A rollback exists for anything a post-install script changes.
  • The old install command is no longer assigned for this package.
  • You know which Macs run macOS 26 and have decided how to treat them.

The next safe decision is small: release one package to ten supervised Macs on macOS 27, remove it from two, and compare the disk with your payload list. Apple’s package distribution page is the place to confirm any change as macOS 27 settles.

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.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on Install a Mac Package With Declarative Management and Remove Its Files When Unassigned. 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.