Sub topic 13
Installing from Disk Images and Installer Packages
This chapter assumes you can use Finder, the Applications folder and System Settings. You should know the difference between an app, a disk image (.dmg) and an installer package (.pkg). The command-line sections are optional and need only Terminal. Earlier chapters covered code signing, notarization, quarantine and Gatekeeper. Here you apply them to the two most common ways a Mac app arrives from the web.
Two containers, two risk profiles
A disk image is a virtual disk. When you open it, macOS mounts it as a volume in Finder. It usually holds an app, which you drag to Applications. Copying the app is the whole installation. Nothing runs with extra privileges, and removing the app later is usually straightforward.
An installer package is a script-driven archive. The Installer app unpacks files to locations the package chooses. Packages can also run scripts before and after the files are copied. Many packages ask for an administrator password, because they write to protected locations such as /Library or /usr/local. Any script in the package then runs with those elevated rights.
| Feature | Disk image (`.dmg`) | Installer package (`.pkg`) |
|---|---|---|
| What you do | Drag the app to Applications | Click through the Installer |
| Can run scripts | Not during the copy | Yes, before and after install |
| Needs an admin password | Rarely | Often |
| Where files end up | Where you put them | Wherever the package decides |
| Removal | Usually delete the app | Often leaves files in several folders |
A .pkg deserves more caution than a .dmg, because you are handing it more power. A .dmg can also contain a .pkg, so check what is inside before you open anything.
Where the safety checks happen
Quarantine and Gatekeeper do not treat a .dmg as a trusted object in itself. The flow below shows the usual path.
The browser adds the com.apple.quarantine attribute to the download. You can see it with the command below.
xattr -l ~/Downloads/Example.dmgWhen you mount a quarantined disk image, macOS verifies it. Apps you copy out of the image normally inherit the quarantine flag, so Gatekeeper checks them again at first launch. Apps copied from a mounted image by Finder keep this behavior. That is why you see the "downloaded from the Internet" confirmation the first time you open a new app.
Step-by-step: installing from a disk image
- Download from the developer's official site, reached by typing the address or using a link you trust. The earlier chapter on vetting sources covers this.
- Compare the checksum if the developer publishes one.
- Double-click the
.dmg. macOS mounts it and shows a window. - Look at the contents before you drag anything. Expect the app and often a shortcut to Applications. Be suspicious of extra items such as "Install.command" or an unexpected
.pkg. - Drag the app to Applications. Do not run it from inside the mounted image.
- Eject the image in Finder (the eject button beside the volume) and move the
.dmgto the Trash. - Open the app from Applications and read the first-launch dialog.
Running from the mounted image causes problems. The app may fail to update itself, and some apps misbehave on a read-only volume. It also keeps the image mounted. Copy first, then eject.
Checking the app before you launch it
Run these before first launch if you want proof beyond Gatekeeper's dialog. The first verifies the signature and that the contents are intact.
codesign --verify --deep --strict --verbose=2 /Applications/Example.appThe next shows who signed it, so you can compare the Team ID with what the developer publishes.
codesign -dv --verbose=4 /Applications/Example.app 2>&1 | grep -E 'Authority|TeamIdentifier'Then ask Gatekeeper's policy whether it would allow the app.
spctl --assess --type execute --verbose=4 /Applications/Example.appA good result reports accepted and a source such as Notarized Developer ID. Finally, you can check for an attached notarization ticket.
xcrun stapler validate /Applications/Example.appA failure here is not always a problem. Notarization still works online without a stapled ticket. The ticket only helps offline.
Step-by-step: installing from a package
- Verify the download with a checksum, as above.
- Inspect the signature before opening the installer.
pkgutil --check-signature ~/Downloads/Example.pkgThe output shows whether the package is signed, the certificate chain, and whether it is notarized. A line such as Status: signed by a developer certificate issued by Apple for distribution is what you expect from a legitimate developer. Status: no signature means anyone could have built or altered the file.
- Open the package. Installer shows a license, a destination and a summary. On the destination step, use Customize if it appears, so you can see which components will be installed.
- Enter your password only when you started the installation yourself and you expect the prompt.
- Move the
.pkgto the Trash afterward.
You can also list a package's contents without installing it.
pkgutil --payload-files ~/Downloads/Example.pkgThis lists the paths it would write. Files going to /Library/LaunchDaemons or /Library/LaunchAgents mean the software starts background processes automatically. That is normal for a VPN client or a backup tool. It is unexpected for a simple PDF viewer.
Common errors and what they mean
- "Example is damaged and can't be opened." The file may be incomplete, altered or have an invalid signature. Re-download it and compare the checksum. Do not follow online advice to strip the quarantine attribute as a first step.
- "Cannot be opened because the developer cannot be verified." The app is not notarized or not signed by a known developer. The next chapter covers how to respond.
- The image will not eject ("in use"). An app from the image is still open, or a Finder window or Terminal session is inside it. Quit the app and close those, then retry.
- The app runs only from the image. You did not copy it. Drag it to Applications and open that copy.
- A package fails partway. Check
/var/log/install.login the Console app for the cause. Do not rerun with a different tool that skips checks.
Habits that keep you safe
- Prefer a
.dmgwith a drag-to-Applications layout over a.pkgwhen a developer offers both. - Treat an unexpected request for a password, or for extra permissions after install, as a stop sign.
- Delete installers after use. They are useless once installed and could be mistaken for something else later.
- If an image or package tells you to run a command in Terminal to "unlock" it, stop. Legitimate installers do not need that.
Exercise
You download Example.pkg from a site you found through a search ad. pkgutil --check-signature reports "Status: no signature". The page says to open it anyway. What should you do, and why does a .pkg call for more care than a .dmg?
Show answer
Do not install it. An unsigned package cannot be tied to a known developer, so you cannot tell whether it was altered, and a .pkg can run scripts with administrator rights and write to system locations. Go to the developer's official site by typing the address, and download the package from there. Then verify its checksum and signature. A .dmg normally just holds an app you copy, so nothing runs with extra privileges during the install itself.
Exercise
After dragging Example.app out of a mounted disk image, what are the next two steps, and what does spctl --assess tell you?
Show answer
Eject the disk image and move the .dmg to the Trash, then launch the app from Applications. spctl --assess reports whether Gatekeeper's policy would allow the app to run and the source of approval, for example "accepted source=Notarized Developer ID".