Skip to content

pkgbuild command in MacOS

The MacOS pkgbuild command is a powerful tool that allows users to create package installer files for their applications. With pkgbuild, you can easily bundle your software into a convenient installer package that streamlines the installation process for end-users. This command provides various options for customizing the package, including specifying the payload contents, scripts to run before and after installation, and metadata information. By mastering the pkgbuild command, you can simplify the deployment of your software on MacOS systems and ensure a smooth user experience.

Terminal window
pkgbuild --root rootpath --identifier com.example.package --version 1.0 output.pkg
OptionDescription
—nopayloadCreate a package without payload files.
—install-location pathSpecifies the install location.
—version versionVersion number of the package.
—root rootpathPath to the root of the package.
—scripts scriptsdirectoryDirectory containing pre-install and post-install scripts.
—identifier packageidPackage identifier.
ParameterDescription
destinationPath where the package is created.
packageidPackage identifier.
packageversionVersion number of the package.
Terminal window
pkgbuild --root /path/to/payload --identifier com.example.package --version 1.0 /path/to/output.pkg

Creates a package using the payload directory specified with the root option and sets the identifier and version.

Terminal window
pkgbuild --root /path/to/payload --scripts /path/to/scripts --identifier com.example.package --version 1.0 /path/to/output.pkg

Creates a package with scripts located in a separate directory using the scripts option.

Terminal window
pkgbuild --root /path/to/payload --identifier com.example.package --version 1.0 --sign "Developer ID Installer: Company Name" --entitlements /path/to/entitlements.plist /path/to/output.pkg

Creates a package with entitlements by specifying the entitlements file with the entitlements option.

Terminal window
pkgbuild --root /path/to/payload --identifier com.example.package --version 1.0 --sign "Developer ID Installer: Company Name" --component-plist /path/to/component.plist --distribution /path/to/custom_distribution.dist /path/to/output.pkg

Creates a package using a custom distribution file specified with the distribution option.

Terminal window
pkgbuild --root /path/to/payload --identifier com.example.package --version 1.0 --sign "Developer ID Installer: Company Name" --ownership preserve --mode preserve /path/to/output.pkg

Creates a package while preserving ownership and permissions of the files in the payload directory.

Terminal window
pkgbuild --identifier com.example.package --version 1.0 --scripts /path/to/scripts /path/to/output.pkg

Creates a package without a payload by omitting the root option and specifying scripts with the scripts option.

Terminal window
pkgbuild --identifier com.example.package --version 1.0 --sign "Developer ID Installer: Company Name" --distribution /path/to/custom_distribution.dist /path/to/output.pkg

Creates a package by defining the necessary components and resources in a custom distribution file.

Sign a package with a Developer ID certificate

Section titled “Sign a package with a Developer ID certificate”
Terminal window
pkgbuild --root /path/to/payload --identifier com.example.package --version 1.0 --sign "Developer ID Installer: Company Name" /path/to/output.pkg

Creates a package and signs it with a Developer ID certificate specified with the sign option.

To use the pkgbuild command in MacOS, execute the following command:

Terminal window
pkgbuild --root /path/to/files --identifier com.example.package --version 1.0 /path/to/output/package.pkg

What is the purpose of the --root option in pkgbuild?

Section titled “What is the purpose of the --root option in pkgbuild?”

The --root option in pkgbuild is used to specify the root directory of the files to be included in the package. This option is essential for defining the source files for the package creation process.

Terminal window
pkgbuild --root /path/to/files ...

How can I assign an identifier to a package using pkgbuild?

Section titled “How can I assign an identifier to a package using pkgbuild?”

To assign an identifier to a package in pkgbuild, use the --identifier option followed by the desired identifier value. This identifier is typically in reverse DNS format to ensure uniqueness.

Terminal window
pkgbuild --identifier com.example.package ...

What role does the --version option play in the pkgbuild command?

Section titled “What role does the --version option play in the pkgbuild command?”

The --version option in pkgbuild sets the version number of the package being created. This version number is important for tracking and managing different versions of the package.

Terminal window
pkgbuild --version 1.0 ...

How can I specify the output path for the package generated by pkgbuild?

Section titled “How can I specify the output path for the package generated by pkgbuild?”

To specify the output path for the package created by pkgbuild, provide the desired path at the end of the command after defining all the necessary options.

Terminal window
pkgbuild --root /path/to/files --identifier com.example.package --version 1.0 /path/to/output/package.pkg

Can pkgbuild be used to customize package installation scripts?

Section titled “Can pkgbuild be used to customize package installation scripts?”

Yes, pkgbuild supports customization of package installation scripts using the --scripts option, allowing you to define pre-installation and post-installation scripts.

Terminal window
pkgbuild --scripts /path/to/scripts ...

How do I create a flat package using pkgbuild?

Section titled “How do I create a flat package using pkgbuild?”

To create a flat package (single bundle format) with pkgbuild, use the --component-plist option and provide the path to a component property list file containing information about the payload.

Terminal window
pkgbuild --component-plist /path/to/component.plist ...

Is it possible to include a license agreement in a package created with pkgbuild?

Section titled “Is it possible to include a license agreement in a package created with pkgbuild?”

Yes, you can include a license agreement in a package created with pkgbuild by using the --license option followed by the path to the license file.

Terminal window
pkgbuild --license /path/to/license.txt ...
  • Create macOS installer packages from components or directories
  • Customize package attributes such as identifier, version, and installation location
  • Include scripts for pre-installation and post-installation tasks
  • Define package requirements and recommendations
  • Create distribution packages containing multiple packages
  • Sign packages with a developer or distribution certificate