6

Does anyone know how to retrieve the version number of a .pkg file which isn't installed yet?

I'd like to use something like pkgutil --pkg-info, but that only works for installed packages.

I've also tried installer -pkginfo -verbose, but that doesn't show the version number.

Is there a built-in command to do this, or alternatively, could someone suggest a one-liner please?

Thanks.

3 Answers 3

5

The best I could come up with was this:

pkgutil --expand package.pkg /tmp/pkg; cat /tmp/pkg/PackageInfo | grep ./Applications | grep -m 1 .app\" | awk '{ print $3, $2 }'; rm -rf /tmp/pkg

Not the most elegant solution, so I'm still searching for a way to do this without having to extract the .pkg first.

1
  • Have you found any better solution yet ?? I do not see any effect to changing package version number when building the pkg file. The final package always seem to replace the existing files anyway, isnt it ?
    – Ahmed
    Aug 15, 2016 at 22:32
3

Variation of @d3Xt3r answer:

tar xOvf PackageName.pkg output.pkg/PackageInfo 2>/dev/null | grep '<pkg-info' \
    | sed "s#.* version=\"\([0-9\.]*\)\".*#\1#"

Advantage is that this is only pipe processing.

Note my package had different structure, there is an extra directory output.pkg which contains file PackageInfo

0

for a package structured as below,

PackageName.pkg
└── Package.pkg
    └── PackageInfo

adapted from @Marek R

the command to extract version information inline is:

tar xOvf "PackageName.pkg" "Package.pkg/PackageInfo" 2>/dev/null | fgrep "<pkg-info" | grep -Po '(?<!-)version="[^"]+"'
New contributor
lwei is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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