How To Install Dmg File On Mac From Command Line



Mac

An intrepid reader asked the following question:
How do you install a .dmg package from the command line?

Many applications are distributed as disk images, a compressed binary format. If you double click a disk image in the Finder, it is mounted automatically. Once mounted, installation of the application is typically done by dragging an icon to the Applications folder. The same can be accomplished from the command line using two commands, hdiutil and cp.

The following steps show the installation of a popular VNC client for OS X called 'Chicken of the VNC'. It can be used as a remote desktop client for Linux, Mac, or Windows hosts.

The download file is named 'cotvnc-20b4.dmg'. Here are the steps needed to install it remotely from the command line.
note: this technique can be used from a local Terminal window or a remote SSH connection.

Mount the disk image

How To Install Dmg File On Mac From Command Lines

  • I would like to install the dmg java package in my MAC OS through the terminal I tried using this command: sudo installer -package jdk-7u51-macos-x64.dmg -target / But I receive this error: ins.
  • Create Installer Open the Terminal in the Utilities' folder. Choose the appropriate command line (in red) depending upon what OS X installer you want. Paste that entire command line from below at the Terminal's prompt.

How To Install Dmg File On Mac From Command Line Command

The first step is to mount (or attach) the disk image. From the command line, use:
hdiutil mount cotvnc-20b4.dmg
I received the following output:

If you double click a disk image in the Finder, it is mounted automatically. Once mounted, installation of the application is typically done by dragging an icon to the Applications folder. The same can be accomplished from the command line using two commands, hdiutil and cp.

A mounted disk image appears on the Desktop, in the Finder, and more importantly shows up as a directory in /Volumes. In this case, the last line of output from hdiutil showed exactly where the disk image was mounted.

Sometimes when a disk image is mounted, it will prompt you to agree to a license first. In that case, the text that would normally appear in a GUI dialog box instead appears in the Terminal window. Once you scroll to the bottom of the agreement, you can type in Y to continue or N to stop. The Firefox disk image is one example of a package that displays a license before mounting.

Install the application

Use the cp command to copy the application to /Applications:
sudo cp -R '/Volumes/Chicken of the VNC/Chicken of the VNC.app' /Applications

The -R switch means to copy recursively, in other words, copy everything from that location including all subdirectories and files below. It is important to leave off the trailing '/' from the 'Chicken of the VNC.app' directory, or the command will not copy the directory itself, just the contents. After entering your password, the application will be installed and ready to use.

Most applications can simply be copied to the /Applications directory. However, some are distributed in a .pkg format and must be installed using the installer command instead of cp. To install a .pkg, use this command:
sudo installer -package /path/to/package -target '/Volumes/Macintosh HD'

Unmount the disk image

To tidy up, return to your home directory and unmount the disk image:
cd ~
hdiutil unmount '/Volumes/Chicken of the VNC/'

You should see this message after the unmount:
'/Volumes/Chicken of the VNC/' unmounted successfully.

Installing applications from a .dmg package at the command line is not something you need to do every day. But it is a nice tool to have if you want to install an application on a remote server or script the installation of a package to a group of desktop Macs.

Posted October 10, 2007 by David Kirk in Apple Mac

Installing OS X from a DMG file can be difficult. With leopard testing and development, many people are having troubles installing from the supplied binary. Here is how it can be accomplished.


Installing OS X from a dmg file format instead of a DVD/CD format seems challenging. Here is how it can be accomplished.

1. Burn it to Dual Layer DVD

OS X is too large to fit on a single layer DVD; however, many macbooks support burning dual layer DVDs. The media is expensive, but for many people this is the easiest option.

Burn it and reboot to it. The OS X will install.

2. Restore the dmg file to an external device

An external hard drive or an iPod in hard disk mode will serve as an excellent booting device as well.

– Copy your dmg file to your current apple desktop.
– In the Utilities Folder in your Applications Folder select Disk Utility
– Select your external device in the left column of the utility
– Click the Restore button
– Drag your dmg to your Source textbox
– Drag your device from the left column to the Destination textbox
– Click the Restore

You will lose any information you have in your external device in this process. After the dmg is restored to the external device, change your boot disk to this device and reboot.

Dragging the source and destination files can be a little confusing. Click the picture below for a larger version.

How To Install Dmg File On Mac From Command Line Windows 10


How To Install Dmg File On Mac From Command Line Download

About David Kirk

David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
View more articles by David Kirk

The Conversation

Follow the reactions below and share your own thoughts.