Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ugultopu/1adf8e08acb87be649d69419cf7aca3c to your computer and use it in GitHub Desktop.
Save ugultopu/1adf8e08acb87be649d69419cf7aca3c to your computer and use it in GitHub Desktop.

UPDATE

Although below are methods to extract the contents of a macOS package without actually installing it, the best way might be to create a blank disk image and install the package to this disk image in order to inspect the package contents. To do so:

  • Open the Disk Utility app.
  • Choose "File > New Image > Blank Image". Alternatively, simply press CMD-N.
  • Set the parameters and click on "Save" to create the blank disk image.
  • After creation, it should be already mounted. If not, you can mount it by navigating to the directory that it is placed at and double clicking on the disk image file.
  • Run the package installer by double clicking on the package file.
  • Select this newly created blank disk image as the destination and install it.
  • If the script is preventing you from installing by saying, for example, "macOS isn't installed", you can:
    • Expand the package (as described in steps below), using pkgutil --expand /Volumes/<disk image where the package file is located at>/<path to the package file> <a non existing path which the extraction will be placed at>.
    • Edit the "Distribution" file under the extraction directory, removing the check for the presence of a macOS installation in the target disk image.
    • Pack it back using pkgutil --flatten <a non existing path which the extraction will be placed at> <a non existing path which the package will be placed at>
    • Double click on <a non existing path which the package will be placed at> to run the installer for the package. This time, it should work, since we removed the check for the presence of macOS installation by editing the "Distribution" file.

An example session of installing Xcode Command Line Tools version 11 to a blank disk image, after creating a blank disk image of sufficient size:

  • Double click on the downloaded "Command_Line_Tools_for_Xcode_11.dmg" disk image. It will mount the disk image and open a Finder window, showing the contents of the disk image. We can close this opened Finder window, since we won't use it.
  • Expand the Command Line Tools package by running pkgutil --expand '/Volumes/Command Line Developer Tools/Command Line Tools.pkg' ~/clt-11
  • Open the ~/clt-11/Distribution file with a text editor and remove the part:
    <volume-check>
        <allowed-os-versions>
            <os-version before="10.16" min="10.14.4"/>
        </allowed-os-versions>
    </volume-check>
  • Repack it using pkgutil --flatten ~/clt-11 ~/clt-11.pkg
  • Double click on this created package file named clt-11.pkg, which is located in your home directory. It will launch the installer for that package.
  • On "Installation Type" step, click on "Change Install Location...". Now you should be able to select the blank disk image that you have created and mounted.
  • Select it, and complete the installation.
  • Now, when you navigate to the disk image (which is under /Volumes/<name of the disk image that you gave while creating it>), the files of the Xcode 11 Command Line Tools should be there.

Best Way

Using the undocumented --expand-full option of the pkgutil command like:

pkgutil --expand-full <path to .pkg file> <a non existing path which the extraction will be placed at>

"Conventional" Way

Might not be working since macOS 10.10, per this answer.

pkgutil --expand <path to .pkg file> <a non existing path which the extraction will be placed at>
cd <a non existing path which the extraction will be placed at>
cat Payload | gunzip | cpio -i

Modern "Conventional" Way

Per this answer, gunzip does not work for Payload files since macOS 10.10, and pbzx must be used instead. pbzx can be found either here or here:

pkgutil --expand <path to .pkg file> <a non existing path which the extraction will be placed at>
cd <a non existing path which the extraction will be placed at>
pbzx -n Payload | cpio -i

Relevant Links

@sebacomars
Copy link

bro ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment