Apple - Why do we install software via `.dmg` files?
DMGs have a few key features which make them superior to plain old zips
- They’re a full file system (meaning they can store file permissions, have custom folder backgrounds, etc)
- They support “mandatory” EULAs before mounting which is nice for legal stuff
- Provide a more reliable execution environment. If you have to do absolute path stuff for installation (which tbh you shouldn’t) you can prepare the DMG, mark it as read-only and use that to install
Really the key feature is that they support the full HFS+ filesystem. Zip (commonly, Linux versions sometimes support permissions) is stupid and only supports bundling files and folders and nothing else. No metadata, just the files.
Mac software can be delivered as as a .app
application bundle (essentially a folder containing all the program resources) or as a .pkg
installer which is a program that installs applications in a similar way to Windows.
Only command line tools are available as plain binaries which would then be copied to somewhere in the user's PATH
such as /usr/local/bin
.
These can be packaged in an OS X/macOS disk image (.dmg
) or a traditional archive format such as .zip
or .tar
.
What is the logic for which software needs to be installed with such a "virtual disk"?
This is largely up to the developer. A .dmg
is just a virtual hard drive not an installer. The choice to utilise a .dmg
is about packaging rather than installation.
If an application is a simple .app
bundle it is self contained and can be run by double clicking it. It is commonly copied to /Applications
for convenience.
In addition to encryption and EULAs on opening, the benefit of a .dmg
over an archive type is branding. .dmg
s can be given custom icons, custom background images and the layout of the contents can be fixed. .dmg
s are commonly also read only so the contents will remain exactly as the developer intended it.
They also force the user to select where they would like an application; when you unzip an archive the contents will typically be extracted to wherever the archive was located. In contrast, .dmg
s will mount in the filesystem and then the .app
bundle must be explicitly copied.
Why doesn't it come as a simple binary file or I don't know what?
A Mac application is more than just a binary. In addition to the the binary (located at <appname>.app/Contents/MacOS/
) an .app
includes a number of resources in <appname>.app/Contents/Resources/
. These resources include icons, graphics and localisation files such as en.lproj
.
Is there any other usage for .dmg files other than Software installation?
Another useful feature about DMGs (since you asked about other uses) is the ability to create an encrypted storage space and store files in that protected space. Useful if you want to protect some files, but not encrypt your entire main hard disk.
See Disk Utility for macOS Sierra: Create a disk image using Disk Utility for more info on creating encrypted .dmg files.