Is it possible to install a .pkg through an ssh connection to a Mac?
3 Answers
/usr/sbin/installer
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. The target is a "device" (see the man page for details or run installer -dominfo). Here / is the main drive, it also accepts devices like "/Volumes/Macintosh HD", or /dev/disk0.
Just in case it's needed; if you want to installer a .pkg without root access:
installer -pkg myapp.pkg -target ~
will install the package in ~/Applications.
-
1@langdon Not sure about the edit. The man page specifically mentions
CurrentUserHomeDirectoryas the name to be used.2025-12-11 14:51:01 +00:00Commented Dec 11, 2025 at 14:51 -
When using this approach, be aware that not all packages will support being relocated to other locations. Much depends on the intent of the package creator and options they encoded within the package.Graham Miln– Graham Miln2025-12-11 17:27:02 +00:00Commented Dec 11, 2025 at 17:27
Install all .pkg files from the current folder to /Applications (or whatever target folder is configured in the package):
for f in *.pkg; do
sudo installer -verbose -pkg "$f" -target /
done
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 want to see which specific folders a pkg installer writes to and which 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.pkgfile is selected. Pressing spacebar in Finder with the selected file should work too. A similar shareware (nagware) app — Pacifist, can be used for inspecting and unpacking dmg/pkg and other container formats.
Handling files with spaces and special characters
While the for f in *.xyz syntax looks 'clean' and neat, it is considered bad practice in bash because it is likely to fail on file names with spaces, quotes and other special chars. A more foolproof approach is to use find, e.g.
sudo -i
find . -iname "*.pkg" -maxdepth 1 -exec installer -verbose -pkg {} -target / \;
Note:-maxdepth 1 forces find to only search for files in the current folder and avoid traversing nested subfolders.
-
5This doesn't necessarily install to
/Applications- it depends on the package, for example PowerShell for macOS installs to/usr/local.RichVel– RichVel2017-05-24 08:21:07 +00:00Commented May 24, 2017 at 8:21 -
I've put this in an answer as well, but
-target CurrentUserHomeDirectoryis what I've used successfully for Microsoft Edge and Logitech Camera Settings app.RCross– RCross2020-06-29 08:17:06 +00:00Commented Jun 29, 2020 at 8:17 -
Kudos for the "verbose" option — quite useful when you need to see what's wrong during the installation :-(Gwyneth Llewelyn– Gwyneth Llewelyn2024-07-16 14:05:02 +00:00Commented Jul 16, 2024 at 14:05