Is it possible to install a .pkg using a terminal ? (I wanted to install an app through ssh).



The installer command is used to install Mac OS X installer packages to a specified domain or volume. The installer command installs a single package per invocation, which is specified with the -package parameter ( -pkg is accepted as a synonym). It may be either a single package or a metapackage. In the case of the metapackage, the packages which are part of the default install will be installed unless disqualified by a package's check tool(s).

See man installer for the full functionality. Often

sudo installer -pkg /path/to/package.pkg -target /

is all that's needed. Here / is the mount point of Macintosh HD volume. -target accepts path like "/Volumes/Macintosh HD", or /dev/disk0 also.

  • 4
    Note that the -target is a device and not a path. So keep it "/" for most cases. – AlexV Nov 15 '16 at 2:53
  • 1
    @AlexV colour me confused - / is a path and a device is mounted on it. So why would an option that requires a device as an argument accept /? – muru Jun 14 '17 at 2:25
  • 2
    @muru - The documentation calls it a "device", but really it's got its own syntax for defining target (not exactly "unix device node"). According to the installer manpage, it can be a device node (as you expect), the disk identifier (eg disk1s9), the mountpoint (hence "/"), the volume UUID, or any of the install domains listed by installer -dominfo. – sehrgut Mar 28 '19 at 19:09

Just in case it's needed; if you want to installer a .pkg without root access:

installer -pkg myapp.pkg -target CurrentUserHomeDirectory

will install the package in ~/Applications.

  • Is CurrentUserHomeDirectory in this case a special literal token? Or is that to be replaced with $HOME? – coolaj86 Jul 11 '20 at 5:48
  • @coolaj86 It's a literal token – nohillside Jul 26 '20 at 8:57

Install all .pkg files from the current folder to /Applications:

for f in *.pkg ; 
    do sudo installer -verbose -pkg "$f" -target /

As an alternative you can install the packages to your home folder with -target ~. They will end up in /Users/<your_account>/Applications unless a specific path is predefined in the installer.

If you need to see what exactly a pkg installer script contains and what pre- and post-install scripts will be run then check out SuspiciousPackage (freeware, can be installed with brew install --cask suspicious-package), and use quick preview from Finder when a .pkg file is selected. Pressing spacebar in Finder with the selected file should work too.

  • 5
    This doesn't necessarily install to /Applications - it depends on the package, for example PowerShell for macOS installs to /usr/local. – RichVel May 24 '17 at 8:21
  • I've put this in an answer as well, but -target CurrentUserHomeDirectory is what I've used successfully for Microsoft Edge and Logitech Camera Settings app. – RCross Jun 29 '20 at 8:17

You must log in to answer this question.

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