78

Some applications come in .pkg files, and ask for you administrator password, even if all they do is copy the binary to /Applications.

I like to have my applications in ~/Applications, and I do not like to give administrative permissions to anything that is not from the mothership.

Is there a way that I can manually open the .pkg file and pull out the application? There is PackageMaker in the Developer Tools, but that does not seem to do it (it did produce some output that makes me think that there really are no scripts or other pieces in the installer, just the application).

1
  • 2
    Try unpkg.
    – lhf
    Commented Jul 12, 2012 at 11:51

9 Answers 9

86

If you right click it, and click Show Package Contents you'll get a few files in a Contents folder. (Note: if you do not see Show Package Contents you will need to open Terminal.app and run pkgutil --expand mystubbornpackage.pkg path/to/expand)

One is a BOM file (bill of materials) which gets turned into a receipt that you can use to uninstall the app. This file contains a manifest of everything the package will install and where to; to read this file, use the lsbom command.

Most packages (I'm using Office 2008 here) also have an Archive.pax.gz file, this contains everything that Installer will move into the various folders as instructed in the BOM file. Most apps seem to have the .app in this archive, although dragging that to /Applications might leave it without frameworks it needs to run; so you'll have to figure out which other files it needs and where it needs them to get it to work.

Additionally, all packages can log messages, if you hit Cmd-L (or choose the Installer Log option from the Window menu, you can view them as they're generated. This might give you an idea what extra things it's installing, at the very least it's some more information if you're untrusting of the package.

8
  • 6
    I don't get "Show Package Contents" in the right-click menu.
    – Thilo
    Commented Jun 9, 2011 at 23:29
  • 4
    @Thilo If you aren't getting the option to "Show Package Contents" then the pkg file was created as flat file. Apple introduced flat-style pkg's a couple years ago
    – username
    Commented Jun 16, 2011 at 1:14
  • @username: So how do I open those?
    – Thilo
    Commented Jun 16, 2011 at 1:19
  • 13
    pkgutil will do that. You can expand it using pkgutil --expand file.pkg path_to_expand and it'll convert it into a directory style package. Commented Jun 16, 2011 at 10:30
  • 6
    Note: use --expand-full to extract "Payload" file if you have it stackoverflow.com/questions/41166805/…
    – n1313
    Commented Jul 9, 2020 at 3:40
37

In addition to what Matthew Hall said, you can also hit Cmd-I in the Installer app to see what files the installer will install and where.

1
  • 3
    +1. With this I could quickly verify that there is just the application binary in there, no other system-wide stuff.
    – Thilo
    Commented Jun 9, 2011 at 23:35
8

pkgutil --expand was failing for me with the following error:

Error encountered while creating .. Error 17: File exists

But I managed to extract the files with xar instead:

xar -xvf foo.pkg

3
  • 6
    this works for me. but apparently, if you give pkgutil a non-existence directory as destination that makes the 17 error go away.
    – Michael
    Commented Jan 28, 2018 at 20:03
  • Where does it extract it to though? Commented Apr 21, 2020 at 4:31
  • Current dir. @CodyBugstein
    – Teddy C
    Commented Jun 14, 2021 at 13:43
7

If you don't trust the installer enough to give administrative permissions to install, then why do you trust the binary in /Applications?

Pacifist will let you look in package files. This doesn't necessarily just let you "pull out the binary".

3
  • 1
    I do not trust the binary, either. I want to never ever give it administrative permissions (which it should not need anyway).
    – Thilo
    Commented Jun 9, 2011 at 23:30
  • 3
    As long as you don't run the app from any user that has admin privileges, your trust will be upheld. Don't forget that even a user level app can make requests from admin level processes so it's a lot of work to run apps you don't actually trust.
    – bmike
    Commented Jun 18, 2011 at 1:19
  • @ghoppe, It's because defaults sometimes arent optimized for the users but the app creators. Eg instead of installing all the installation junk that comes by default, I can select to take only the files that are of essence. Eg when downloading Mysql / Java / etc.
    – Pacerier
    Commented Dec 10, 2017 at 22:27
4

Alternatively you can try,

sudo installer -pkg ~/Downloads/packagename.pkg -target ~/Applications/

OR

installer -pkg ~/Downloads/packagename.pkg -target ~/Applications/
3
  • That did not work unfortunately. It still insisted to "Installing at base path /" and then asked for the admin password.
    – Thilo
    Commented Jun 9, 2011 at 23:34
  • 1
    It's possible to install to a disk image created with something like hdiutil create -size 200m -fs HFS+ -volname Scratch scratch.dmg and then copy the files to the locations you prefer. You still need the sudo to run the installer unfortunately.
    – mjs
    Commented Aug 25, 2017 at 16:43
  • I get error installer: Error - This version of OS X 10.11 cannot be installed on this computer. Commented Apr 21, 2020 at 4:27
2
  1. After you succeed in opening the package, look for the Archive.pax.gz file that was mentioned earlier.

  2. Create a new empty folder on your desktop naming it whatever you wish. I usually name them "xxxx" or "zzzz" etc. to make typing easier later.

  3. Option-drag a copy of the Archive.pax.gz file into that new folder "xxxx" on your desktop.

    If the file is inside of read-only media you can just drag it to your "xxxx" folder without the Option key to create a copy.

  4. Now open Terminal.app and at the command line navigate to your new "xxxx" directory and list the directory's contents to confirm that your Archive.pax.gz file is there:

    cd ~/Desktop/xxxx
    ls -al
    
  5. Now there are two simple commands to enter:

    gunzip -v Archive.pax.gz
    

    Gzip will tell you that it has replaced "Archive.pax.gz" with "Archive.pax") Now list the directory's contents again to confirm this.

    pax -r -f Archive.pax
    

    (You must separate -r and -f, as -rf will not work)

  6. Finally, list the directory's contents again with ls -al. In addition to your Archive.pax file you will now see a directory hierarchy probably containing one or more directories.

    The files in that directory hierarchy will illustrate to you where the OS X installer would install files on your system as if your "xxxx" directory was the root directory "/".

  7. You may then manually copy those files to their destinations if you wish.

2
  • 3
    In other words cd ~/Desktop; cp Package.pkg/Contents/Archive.pax.gz .; gunzip -v Archive.pax.gz; pax -r -f Archive.pax. You don't need to describe everything at that level of detail.
    – Lri
    Commented Aug 14, 2011 at 0:30
  • 6
    Lri, I gave that amount of detail so users at any level of expertise would be able to follow it and be successful. Granted, your cryptic version would achieve the same results. However, other users reading this in the future who may not be familiar with the command line might be hopelessly lost.
    – stargood
    Commented Aug 15, 2011 at 4:56
2

The best tool for inspecting package files is Suspicious Package. It also allows you to copy files out of the package.

Not only will it provide all the information you need in the app it also install a Quick Look plug in so just selecting the package file and hitting the space bar opens up a window with the most essential information.

1

UnArchiver did the trick.

Install UnArchiver, open UnArchiver; while it is open - double click on that pesky MAMP_MAMP_3.5.pkg

Follow the steps to install MAMP.

0

The Unarchiver can do this; it will do the same as pkgutil --expand but using drag-and-drop. It's a better replacement for Apple's Archive Utility.app anyways.

You must log in to answer this question.

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