One of my clients contacted me asking me if there’s a way to install a .dmg using macos terminal. This is something I always wondered. It was great he contacted me, so I can be forced to learn this method.

It is easier than what I expected. After you download the .dmg you need to ‘mount’ the .dmg by running the below command in your Terminal:

hdiutil attach /path/to/file.dmg

You will see the .dmg mounted usually on your desktop. After you can use the below options.

Two options for installing a .dmg using the Terminal

# install app
sudo cp -rf /Volumes/APP_NAME.app /Applications
# install pkg
sudo installer -pkg /Volumes/"$package" -target /

What I found is that sometimes there is an ‘app’ installer inside the .dmg that you cannot just move to the /Applications folder. In this case you may need to find the ‘Installer’ within the app:

sudo open /path/to/YourInstaller.app/Contents/MacOS/YourInstaller

The above doesn’t work all the time. Sometimes you need to run the installer:

./path/to/YourInstaller.app/Contents/MacOS/YourInstaller

So, using the pkg is very easy to deploy .dmg using macos terminal especially when deploying to many macs instead of an Installer.app. Contact me if you have any questions. Also, check out my cool hats designs.

Leave a comment

Your email address will not be published. Required fields are marked *