30

When I want to install software, I typically download a .dmg (Disk iMaGe) file. When I open it, this .dmg file looks like what I would call a "virtual disk" (hence its name I presume) and is listed in Finder under devices. It is also listed in Disk Utility under Disk Images and it seems like it can be erased or unmounted just like any other disk.

  • What is the logic for which software needs to be installed with such a "virtual disk"?
  • Why doesn't it come as a simple binary file or I don't know what?
5
  • 13
    Installing software can always cause damage.
    – dessert
    Commented Oct 12, 2017 at 8:07
  • 1
    A simple binary file would be an installer. With DMG you just copy the application without running an installer. Commented Oct 12, 2017 at 8:30
  • 10
    Most Mac apps look like single files, but in reality are "application bundles", basically folder with many files inside. Finder displays it as single entity, but you can right click on them and select "Open contents" to inspect files inside. So, "simple binary" won't work. Commented Oct 12, 2017 at 10:40
  • 4
    History: blog.barthe.ph/2011/04/05/dmg_history Commented Oct 12, 2017 at 21:15
  • The last paragraph should be a separate question as it is giving rise to separate answers
    – mmmmmm
    Commented Oct 13, 2017 at 17:39

3 Answers 3

37

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.

14
  • 14
    Additional points: starting in 10.12, .dmg files can be code-signed for integrity (.zip files can contain signed code, but cannot themselves be signed in a way that'll survive downloading). Also, the "simple binary" option doesn't work at all, because most macOS software comes as packages -- folders with complex (hidden) internal structure -- rather than plain files. Commented Oct 12, 2017 at 5:25
  • 10
    "Zip is stupid and only supports..." - I disagree with that assessment. Just because something is simple doesn't mean it's stupid. Simplicity is a virtue, and rarely is (often invisible) file metadata of any value in a distributed installer.
    – Dai
    Commented Oct 12, 2017 at 10:26
  • 15
    @Dai he means stupid as in dumb; the program doesn’t know what it’s doing - not that it’s useless.
    – Tim
    Commented Oct 12, 2017 at 12:04
  • 4
    I suppose ZIP is not too much of a good comparison. Why not e.g. compressed TAR like tar.gz? It does store permissions.
    – Ruslan
    Commented Oct 12, 2017 at 14:07
  • 2
    @Dai, "rarely is (often invisible) file metadata of any value in a distributed installer" -- true on many other platforms, but Apple has a long history of storing critical content (ie. icons!) in "resource forks" (these days, xattrs). Commented Oct 13, 2017 at 2:12
3

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. .dmgs can be given custom icons, custom background images and the layout of the contents can be fixed. .dmgs 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, .dmgs 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.

2

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.

2
  • Encryption however is already doable without the need for .dmg. Doesn't Unix encrypt?
    – Pacerier
    Commented Feb 14, 2018 at 14:30
  • @ Pacerier -- oh for sure -- like everything with Linux/Unix, there's more than one way to do something.
    – Ken
    Commented Feb 15, 2018 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .