MacOS – Command to find out the version number of a .pkg file

command lineinstallmacospkgterminal

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.

Best Answer

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.