104

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.

philant
  • 2,353

6 Answers6

121

First, mount the dmg image : 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: hdiutil detach /Volumes/<image>.

philant
  • 2,353
  • 1
    I did that with Docker.dmg and I had no <image>.pkg so that dit not work – Dimitri Kopriwa Oct 27 '19 at 15:56
  • mine is <image>.app instead of <image>.pkg after doing sudo hdiutil attach <image>.dmg, how can i do then? – jack Mar 27 '21 at 18:13
  • 3
    @jack If there is an .app within a DMG you usally can just drag/copy it to /Applications. – nohillside May 19 '22 at 06:01
  • Sometimes application inside dmg is distributed as app folder. In such case you need to copy it as in this answer https://apple.stackexchange.com/a/308510/452756 – Trismegistos Jan 16 '23 at 08:42
  • It's amazing how complex it is to perform such a basic operation on a macOS CLI. Looks like they forgot about the "Think" in "Think Different". – Martin Jan 08 '24 at 09:43
23

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.

trojanfoe
  • 395
19

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.

Jawa
  • 2,484
Jan ATAC
  • 291
14

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 "$volume" | grep .pkg | head -1)
      sudo installer -pkg "$volume"/"$package" -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.

1

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

Daniel
  • 34,803
Sanjuro
  • 75
  • open didn't do anything, just exit, without error message. – philant Dec 05 '12 at 09: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 05 '12 at 12:19
  • Helpful, though maybe not exactly what the OP needed. Thanks. – Danny Whitt Feb 09 '14 at 12:06
  • I found that open -W </path/todmg> worked (it waits until the volume has actually appeared). – gib Jun 08 '20 at 10:20
0

After you've downloaded the.dmg file. By pressing the right button, the file must be mounted and opened with the same picture.DiskImageMounter(Default).

enter image description here .

The. app file will then be shown. When the. app file appears, open the terminal and navigate to the write directory where the file is located. and type open -a/ExistingFileName.app in the command prompt, then press enter. This is how I use the macOS terminal to launch the.dmg file.

Shofiq
  • 1
  • You can also just double-click the DMG file to open it. Also please be more specific about what you mean with "open the terminal go to the directory write open -a/FileName.app and hit enter", this seems to lack some details. – nohillside Jan 25 '22 at 12:05
  • The OP only has "an ssh access", so he cannot open the .dmg this way. – IT-bob Jun 01 '23 at 07:42