How to create a DMG installer for a Mac app
By Flavio
Tagged: Mac
Package your Mac app in a drag-to-Applications DMG, sign and notarize it, verify the download, and attach it to a GitHub release.
A DMG gives your Mac app a familiar install screen. Open the download, drag the app to Applications, and eject the disk image.
You can build that window with tools macOS already includes. The tricky part is getting the release steps around it right: the app inside needs its own valid signature, and the final DMG needs notarization and a real download test.
We’ll build the disk image, arrange its icons, and upload it as a GitHub release asset. I’ll use Note Repo as the example app name in the commands below, so swap in your own app name and signing identity as you follow along.
If you haven’t signed and notarized the .app bundle yet, see how to avoid the “Open Anyway” message when building macOS apps first.
What a DMG installs
A disk image mounts as a volume in Finder. The .app is a directory holding your executable and resources, and the Applications icon in the window is just a symlink to the user’s /Applications folder.
Dragging the app onto that icon copies the bundle into place, with no install script needed.
This works well for a self-contained app bundle. If your app needs root privileges, a system service, or files placed in protected folders, you’ll need a separate installer and authorization setup instead of a drag-and-drop DMG.
You can also ship a Mac app as a ZIP. Use a DMG when you want a clearer install window, and keep a ZIP alongside it if an updater already expects one. My GitHub Releases updater looks for ZIP assets, so replacing the ZIP with a DMG would break updates.
Start with the release app
For this walkthrough, put your finished app here:
dist/
Note Repo.app
Make sure it’s a release build, and double-check the displayed version, bundle identifier, minimum macOS requirement, and supported architectures before you package it.
Direct distribution requires a Developer ID Application signature, which comes with a paid Apple Developer Program membership. If you publish the source code, people can still build the app locally without paying for a membership of their own. See free and paid Apple developer accounts for what each tier lets you ship.
List the signing identities installed on your Mac:
security find-identity -v -p codesigning
For my releases, the identity is Developer ID Application: Flavio Copes (DGFKNTAG99). Yours will have your own name and team identifier.
It’s best to configure signing and Hardened Runtime in your build settings. For a small app with no embedded frameworks, helpers, or special entitlements, you can sign it with a command like this:
codesign --force --options runtime --timestamp \
--sign 'Developer ID Application: Flavio Copes (DGFKNTAG99)' \
'dist/Note Repo.app'
Don’t run that command on an Electron app or a bundle with nested executables. Each nested binary has to be signed in the right order with its own entitlements, so let your build system’s distribution workflow handle it.
Apple advises against using --deep as a signing shortcut, though it’s useful when verifying nested code:
codesign --verify --deep --strict --verbose=2 'dist/Note Repo.app'
codesign --display --verbose=4 'dist/Note Repo.app'
In the second command’s output, check that the signing authority and team identifier match your Developer ID certificate:
Check Apple’s notarization requirements too. You need secure timestamps, Hardened Runtime, and no leftover development entitlements before you wrap the app in a disk image.
Prepare a clean staging folder
Next, create a folder that holds only what should show up in the install window.
Run these commands in the same terminal session:
mkdir -p dist
DMG_STAGE=$(mktemp -d /tmp/note-repo-dmg.XXXXXX)
ditto 'dist/Note Repo.app' "$DMG_STAGE/Note Repo.app"
ln -s /Applications "$DMG_STAGE/Applications"
ditto copies the bundle while keeping its structure intact, and the symbolic link points to /Applications on whatever Mac mounts the image (we aren’t copying your Applications folder into the download).
Check what’s inside the staging folder before moving on:
ls -la "$DMG_STAGE"
readlink "$DMG_STAGE/Applications"
You should only see the app and the Applications link. Keep source files, test fixtures, personal documents, and credentials out of this folder.
Copying the finished app into staging keeps your original build untouched while you arrange the Finder window. From here on, don’t edit anything inside the .app bundle, because changing a signed file breaks its signature.
Create an editable disk image
Start with a writable image while you arrange the window. Later we’ll convert it into the read-only file people download.
Use hdiutil, which ships with macOS:
hdiutil create \
-volname 'Note Repo' \
-fs HFS+ \
-format UDRW \
-srcfolder "$DMG_STAGE" \
'dist/Note Repo-layout.dmg'
UDRW creates the editable image, and setting the filesystem explicitly keeps this small volume independent of whatever filesystem your source folder uses.
Mount it:
hdiutil attach 'dist/Note Repo-layout.dmg'
Check the mounted path in the output. Normally it’s /Volumes/Note Repo, though macOS picks a different path if another volume already uses that name. Use whatever path it prints in the next steps.
Arrange the drag-to-Applications window
Open the mounted volume in Finder and switch to icon view with Command-1.
Then open View → Show View Options with Command-J. Pick an icon size that makes the app and Applications folder easy to recognize, and set sorting to None so you can place them yourself.
Put the app on the left and Applications on the right, then resize the Finder window so both fit without scrolling. Close the window after arranging it, and reopen the volume to make sure Finder saved the layout.
Finder stores view settings in a .DS_Store file on the writable volume. This is one of the few places where that file belongs in a release.
You can add a background illustration, though I’d start with the plain window. It stays readable across different display settings and gives you fewer files to maintain. The install instructions in your README can say: “Drag Note Repo to Applications, then eject the disk image.”
Don’t launch the app yet. We’ll test running the installed copy once the final DMG is built.
Eject the volume through Finder, or detach its exact mounted path:
hdiutil detach '/Volumes/Note Repo'
If detaching says the volume is busy, close any Finder windows or terminal sessions using it and try again. Don’t force-eject while Finder might still be writing the layout.
Convert it to the download format
Convert the editable image into a compressed, read-only image:
hdiutil convert 'dist/Note Repo-layout.dmg' \
-format UDZO \
-o 'dist/Note Repo-download.dmg'
UDZO is the read-only, zlib-compressed format described in Apple’s packaging guide. Keep the editable image around locally as an intermediate file. The download asset is Note Repo-download.dmg.
Verify the image’s integrity:
hdiutil verify 'dist/Note Repo-download.dmg'
This checks the disk image container itself. We’ll verify Gatekeeper and launch the app after signing and notarizing.
If you change the app, start over from staging. If you only tweak the window layout, you can edit the writable image and convert it again. Either way, the new DMG has to go through the remaining release steps again.
Sign the disk image
The DMG gets its own signature, separate from the app inside. Use the Developer ID Application certificate here too:
codesign --timestamp \
--identifier com.flaviocopes.noterepo.disk-image \
--sign 'Developer ID Application: Flavio Copes (DGFKNTAG99)' \
'dist/Note Repo-download.dmg'
codesign --verify --verbose=2 'dist/Note Repo-download.dmg'
Pick a disk-image identifier that belongs to your product and is distinct from the app’s bundle identifier.
This only signs the outer container, so any unsigned helper inside the app will still fail notarization. That’s why we checked the .app bundle first.
Notarize and staple the final DMG
Notarization sends your DMG to Apple’s automated security check. It’s separate from Mac App Store review.
Save your notarization credentials in Keychain with this interactive command:
xcrun notarytool store-credentials notary
Follow the prompts to enter your account and authentication details. If you use an Apple ID, enter an app-specific password as described in Apple’s custom workflow.
Next, submit the signed DMG using the saved notary profile so your password stays out of your commands:
xcrun notarytool submit 'dist/Note Repo-download.dmg' \
--keychain-profile notary \
--wait
Save the submission ID and wait for an Accepted result before moving on, since a finished upload only means Apple received the file.
If Apple rejects it, fetch the submission log with xcrun notarytool log, passing that ID and the same Keychain profile. The log tells you which file failed so you can fix it, rebuild the DMG, and submit again.
Once it’s accepted, staple the ticket onto the DMG:
xcrun stapler staple 'dist/Note Repo-download.dmg'
xcrun stapler validate 'dist/Note Repo-download.dmg'
Stapling attaches the ticket directly to the file so macOS can verify it offline.
When you submit a DMG, Apple inspects the app inside it automatically, so you don’t need to submit nested items separately. If you also ship a ZIP download, handle it a bit differently: notarize and staple the .app first, then zip it up, because ZIP files can’t hold a stapled ticket.
Test the file people will download
Mount the final DMG and check its window again. Drag the app into Applications, eject the image, and launch the installed copy.
Do this on a separate Mac, a clean user account, or a test VM. Your development machine can hide missing resources, saved permissions, and first-launch bugs.
Run this against the app you just copied into Applications to check its signature and Gatekeeper assessment:
codesign --verify --deep --strict --verbose=2 '/Applications/Note Repo.app'
spctl --assess --type execute --verbose=4 '/Applications/Note Repo.app'
The app should launch cleanly from Applications after the image is ejected. Walk through its main workflow and quit it. If it tries to read a resource from the mounted disk image, fix that before shipping.
Test a browser download of the release too, since that adds the quarantine metadata a local copy doesn’t have. If macOS blocks it, check the signature, the notarization log, and the exact file you downloaded instead of telling people to disable Gatekeeper.
Attach it to a GitHub release
Generate the checksum only after signing and stapling, because both steps change the file:
shasum -a 256 'dist/Note Repo-download.dmg'
To attach the DMG to an existing release, use GitHub CLI to upload the asset:
gh release upload v1.0.0 'dist/Note Repo-download.dmg' \
--repo flaviocopes/note-repo
Swap v1.0.0 for the release tag that matches the app inside your DMG. If you’re creating a new release, gh release create can attach the file right away, and --verify-tag makes sure the tag already exists remotely.
List the supported macOS versions and architectures in the release notes, along with the checksum and short install instructions. If there’s also a ZIP for automatic updates, label both downloads clearly so people know which one to pick.
Download the uploaded DMG into a fresh folder, compare its checksum against your local final copy, and run through the install test one more time on the exact file your users will get. Later, I check how many times it was downloaded.
Want me to talk about your product? You can sponsor this site.
Related posts about mac: