installer - macOS


Overview

The installer command in macOS is used to install and manage software packages. It primarily works with .pkg and .mpkg files — package formats used by macOS for software distribution. The installer command is powerful when deploying software in a scriptable, repeatable manner, such as in system setups, automated deployments, and other managed IT environments.

Syntax

The basic syntax of the installer command is as follows:

installer [options] -pkg <path_to_package> -target <install_volume>

Parameters:

  • <path_to_package>: The file path to the package (pkg or mpkg) that you want to install.
  • <install_volume>: The path to the volume or directory where you want to install the package.

Options/Flags

  • -pkg <path>: Specifies the path to the package file.
  • -target <target>: Specifies the target disk, volume, or directory for installing the package.
  • -applyChoiceChangesXML <path>: Specifies a path to an XML file that contains changes to the choices available in the package.
  • -verbose: Provides detailed output during the installation process.
  • -verboseR: Even more verbose, providing extensive installation details.
  • -dumplog: Dumps the installation log to the terminal.
  • -plist: Outputs the installation log in plist format.
  • -volinfo: Outputs information about the volume intended for installation.
  • -showChoices: Displays the installation choices defined in the package.
  • -showChoicesAfterApplyingChangesXML: Shows how choices change after applying an XML choice changes file.
  • -showChoicesXML: Outputs the choices in XML format.
  • -context <context>: Executes the installation in a specified context.
  • -allowUntrusted: Allows installation of packages that have not been digitally signed or certified.

Examples

  • Install a package to the default volume:
    sudo installer -pkg /path/to/package.pkg -target /
    
  • Install a package to a specified volume with verbose output:
    sudo installer -verbose -pkg /path/to/package.pkg -target /Volumes/Secondary
    
  • Displaying available choices in a package:
    installer -pkg /path/to/package.pkg -showChoices
    

Common Issues

  • Permission Errors: Ensure you’re running installer with sufficient privileges; use sudo to elevate your permissions.
  • Invalid Package Path: Double-check the path to the .pkg file. If the path contains spaces, enclose it in quotes.
  • Untrusted Certificate: If you encounter issues regarding untrusted packages, consider using the -allowUntrusted flag, although be cautious about installing unverified software.

Integration

The installer command can be combined with ssh for remote installations, or with scripts to automate installations across multiple machines:

ssh admin@example.com 'sudo installer -pkg /path/to/package.pkg -target /'

Combine it with curl to install packages directly after download:

curl -O http://example.com/package.pkg && sudo installer -pkg package.pkg -target /
  • pkgutil: This command manages installed packages and can query and manipulate installed package receipts.
  • softwareupdate: Use this command to manage macOS system updates.

For additional information on the installer command, refer to the man pages by running man installer in the terminal or visiting the official Apple developer documentation.