7

In a BASH script I need to check if gcc, g++, cpp, make, libpng devel, zlib devel, git, Java (including devel files), ant and pkg-config are available on Mac OS X and if not, I need to prompt user to install them.

This is easy task on Linux as it has package management tools, but I have no idea how to do this in Mac OS X shell. E.g. on openSUSE I can use rpm -q and zypper in, od Debian-based distros dpkg-query and apt-get install. But how to do it on a Mac?

7

Apple's package management system is often subject to criticism. The utility pkgutil can be used to list and query the package receipts.

List all the packages installed with Apple's installer

     pkgutil --pkgs

Regex for a package id

    pkgutil --pkgs=.\+Xcode.\+

List all the files in a package id

    pkgutil --only-files --files com.apple.pkg.update.devtools.3.2.6.XcodeUpdate

Then again you could use lsbom and read the bom files in /var/db/receipts

Users also install other package management systems such as MacPorts, fink, or Homebrew. Or compile their own in whatever prefix. pkgutil will not list packages installed by these methods.

If your target operating system is OS X10.9 or OS X 10.10 then

    gcc --version

Either the command will output the gcc version or you will be prompted to install the XCode command line tools. gcc, g++, cpp, make, and git will be installed along with other tools. The Java package is offered from Oracle. You could test with java --version though you'll need to familiarize yourself with Apple's frameworks, plugins, and bundles to search for header files. pkgutil would be a good candidate for this process.

The other packages you mentioned could possibly be compiled with in a shell script or compiled and put into an Apple installer package then installed via a shell script. There isn't an easy method.

  • So that I can not rely on pkgutil when querying for installed packages? I'd like to check on as basic OS X as possible without relying on 3rd party tools like MacPorts, Flink or Homebrew if some packages are installed and if not, install them... – Tilia Jun 2 '15 at 14:34
1

The first thing that comes to mind is system_profiler:

system_profiler SPSoftwareDataType

The output of the above command will look similar to a yum info There are plenty of other options to throw at this utility. man system_profiler should get you on the right track. This blog entry will provide you with a little more information.

  • As far as I understand this tool from its man, it seems I can only verify if particular software is installed, which is important step, just only the first step. Is there something like zypper or apt-get for Mac? – Tilia Jun 2 '15 at 13:04
  • Sadly the man page doesn't outline all of the options in system_profiler. If you check out the blog I linked you might get a little more info. – h3rrmiller Jun 2 '15 at 14:32
  • OK, thank You for details. But still I see only possibilities for querying... – Tilia Jun 2 '15 at 14:44
  • @h3rrmiller It appears that as of 2019-01-13 the link to blog entry does not seem to work, although I found useful info via this link macstuff.beachdogs.org/blog/… – condiosluzverde Jan 13 at 6:07
0

if this package has a binary that can be found, you can do -

package_name=<packge-name>
t=`which $package_name`
[ -z "$t" ] && echo "the $package_name isn't installed!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.