42

I want to install a dmg file on a remote server. All I have is an ssh access. Since a DMG is a disk image, I tried to mount it, but mount does not seem to recognize its format.

file says my dmg file is a VAX COFF executable.

59

First, mount the dmg image : sudo hdiutil attach <image>.dmg

The image will be mounted to /Volumes/<image>. Mine contained a package which i installed with: sudo installer -package /Volumes/<image>/<image>.pkg -target /

Finally unmount the image: sudo hdiutil detach /Volumes/<image>.

  • I wrote a blog post about installing .dmg files that you can save as a recipe for the apps you use on your machine. Hope this helps: grantgeorge.io/install-dmg-recipe – grant May 26 '15 at 19:27
17

You should be able to mount the .dmg using:

hdiutil attach /path/to/file.dmg

And then copy its contents (which appears in /Volumes) where ever you like.

4

I had to mount and copy the .app to /Applications folder. For Etcher.app:

First as @trojanfoe said :

sudo hdiutil attach /Users/janatac/Etcher-1.2.1.dmg

Then

sudo cp -R /Volumes/Etcher\ 1.2.1/Etcher.app /Applications

You then have your application in /Applications folder

Don't forget to unmount the volume :

sudo hdiutil unmount /Volumes/Etcher\ 1.2.1/

Got it working after reading instructions from a blog post.

3

If you want to script the install it requires a few more steps since the name of the .dmg file, the name of the Volume created, the name of the application, and the name of the device that needs to be detached can all be different. Plus they can have spaces in them.

Also a .dmg can have an .app file or a .pkg file in it and these require different behavior.

Here's a bash function to install a dmg from a remote URL:

# usage: installdmg https://example.com/path/to/pkg.dmg
function installdmg {
    set -x
    tempd=$(mktemp -d)
    curl $1 > $tempd/pkg.dmg
    listing=$(sudo hdiutil attach $tempd/pkg.dmg | grep Volumes)
    volume=$(echo "$listing" | cut -f 3)
    if [ -e "$volume"/*.app ]; then
      sudo cp -rf "$volume"/*.app /Applications
    elif [ -e "$volume"/*.pkg ]; then
      package=$(ls -1 | grep *.pkg | head -1)
      sudo installer -pkg "$volume"/"$package".pkg -target /
    fi
    sudo hdiutil detach "$(echo "$listing" | cut -f 1)"
    rm -rf $tempd
    set +x
}

Note if your .dmg has an .app file that runs to install the program, then you will need to do something different again.

  • This will only work for dmg‘s containing ready-to-run apps, not for packages or installer apps. – nohillside Jan 7 '18 at 19:58
  • @patrix can you give me some examples of packages and installer apps that I can test against to refine the answer? – voutasaurus Jan 7 '18 at 20:11
  • Packages are easy (end in .pkg), but an installer app looks the same as a real one – nohillside Jan 7 '18 at 20:19
  • this does not detach the file. hdiutil: detach failed - No such file or directory – Nicholas DiPiazza Apr 9 '18 at 19:14
  • 1
    @NicholasDiPiazza I wish Apple would make this easier by providing and enforcing a single easy to use standard and giving developers tools to automatically convert their existing installers to use the new standard. – voutasaurus Apr 27 '18 at 22:21
1

You could try the command open disk://host.tld/image.dmg.

  • open didn't do anything, just exit, without error message. – philant Dec 5 '12 at 9:36
  • 2
    Yes it does. I just tested it. It won't display anything until the disk image has been completely mounted, so you will have to wait a minute or so before it appears in /Volumes. (It works if you ssh in and type open path/to/file.dmg. I don't think disk://host.tld/ works though.) – daviewales Dec 5 '12 at 12:19
  • Helpful, though maybe not exactly what the OP needed. Thanks. – Danny Whitt Feb 9 '14 at 12:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.