Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homebrew: how to list installed bottles and their OS version?

Tags:

macos

homebrew

I recently upgraded Mac OS X to Yosemite and I'd like to make sure that each package I have currently installed is a Yosemite bottle.

How can I list installed bottles and their OS version, so to eventually uninstall/install them?


EDIT Grepping the string "bottled" won't work because it is there anyway if a bottle is available for the package, but you can still compile from source. For example I've just built yasm from source and brew info yasm returns:

yasm: stable 1.3.0 (bottled), HEAD
Modular BSD reimplementation of NASM
http://yasm.tortall.net/
/usr/local/Cellar/yasm/1.3.0 (44 files, 3.3M) *
  Built from source
[...]
like image 794
mindrones Avatar asked Mar 15 '23 04:03

mindrones


2 Answers

The fastest way to list all bottled formulae is to query the JSON output of brew info --json directly (this requires jq):

brew info --json=v1 --installed | jq -r "map(select(.installed[].poured_from_bottle) | .name) | unique | .[]"

Here, brew info --json=v1 --installed provides the JSON-formatted info for all installed formulae. jq processes this (use it without arguments for a beautified output). select(.installed[].poured_from_bottle) picks every formula where there's at least one bottled version installed, and map(... | .name) returns the associated names. | unique ensures that, in the case where there are multiple bottled versions installed, the formula name is returned only once, | .[] breaks the returned array of names into a list, each on a separate line, and -r strips the quotes from the JSON output, leaving a format that can be passed into other shell commands.

That's a bit complicated to remember every time, but you can put this command into a shell script:

#!/bin/bash

#:  * `bottled` [<options>]:
#:
#:  List all bottled formulae which are currently installed.
#:
#:          --versions                   Show the version number for bottled 
#:                                       formulae
#:      -h, --help                       Show this message.
#:
#:  (`brew bottled` requires `jq`. Use `brew install jq` to install.)

if type jq &>/dev/null; then
  case $1 in
    --versions)
      brew info --json=v1 --installed | \
        jq -r "map(select(.installed[].poured_from_bottle) | .name + \" \" + .installed[].version) | .[]"
      ;;
    *)
      brew info --json=v1 --installed | \
        jq -r "map(select(.installed[].poured_from_bottle) | .name) | unique | .[]"
      ;;
  esac
  exit $?
else
  echo '`brew bottled` requires jq. Use `brew install jq` to install.'
  exit 1
fi

Call it brew-bottled, make it executable (chmod a+x brew-bottled) and place it somewhere in your path (e.g. /usr/local/bin). Now you can call it as an external command with brew bottled to list your bottled formulae. (As an added bonus, the --versions switch will include version information, similar to brew list --versions, including multiple bottled versions of the same formula.)

So, if you wanted to, say, rebuild all bottled formulae from source, you could then pipe this to through xargs:

brew-bottled | xargs brew reinstall -s

(Leave off the -s to simply reinstall the current OS bottles.)

Unfortunately, there seems to be no way to determine what macOS version's bottle is currently installed, so you'd be looking at reinstalling all bottled formulae to be sure.

like image 114
Chris Avatar answered Apr 01 '23 00:04

Chris


Updated Answer

There seems to be an INSTALL_RECEIPT.json in each homebrew package inside /usr/local/Cellar, e.g. this for OpenCV

/usr/local/Cellar/opencv/2.4.12/INSTALL_RECEIPT.json

It is standard JSON, so you can parse it like this without needing and additional tools:

python -mjson.tool /usr/local/Cellar/opencv/2.4.12/INSTALL_RECEIPT.json

and you get this - which may help your cause... maybe.

    {
    "HEAD": "d60f75135ecf1a667539700ad7916cefbcc98480",
    "built_as_bottle": false,
    "compiler": "clang",
    "poured_from_bottle": false,
    "source": {
        "path": "/usr/local/Library/Taps/homebrew/homebrew-science/opencv.rb",
        "spec": "stable",
        "tap": "homebrew/homebrew-science"
    },
    "stdlib": "libcxx",
    "time": 1444317226,
    "unused_options": [
        "--32-bit",
        "--with-java",
        "--with-qt",
        "--with-tbb",
        "--without-tests",
        "--without-opencl",
        "--with-cuda",
        "--with-quicktime",
        "--with-opengl",
        "--with-ximea",
        "--without-numpy",
        "--without-python",
        "--c++11",
        "--without-eigen",
        "--with-gstreamer",
        "--with-jasper",
        "--with-libdc1394",
        "--without-openexr",
        "--with-openni",
        "--with-ffmpeg"
    ],
    "used_options": []
}

You can also get the output of the brew info command in JSON format, e.g.:

brew info imagemagick --json=v1 | jq "."
[
  {
    "name": "imagemagick",
    "full_name": "imagemagick",
    "desc": "Tools and libraries to manipulate images in many formats",
    "homepage": "http://www.imagemagick.org",
    "oldname": null,
    "versions": {
      "stable": "6.9.2-3",
      "bottle": true,
      "devel": null,
      "head": "HEAD"
    },
    "revision": 0,
    "installed": [
      {
        "version": "6.9.2-3",
        "used_options": [
          "--with-x11"
        ],
        "built_as_bottle": null,
        "poured_from_bottle": false
      }
    ],
    "linked_keg": "6.9.2-3",
    "keg_only": null,
    "dependencies": [
      "xz",
      "libtool",
      "pkg-config",
      "jpeg",
      "libpng",
      "libtiff",
      "freetype",
      "fontconfig",
      "little-cms",
      "little-cms2",
      "libwmf",
      "librsvg",
      "liblqr",
      "openexr",
      "ghostscript",
      "webp",
      "fftw",
      "pango"
    ],
    "conflicts_with": [],
    "caveats": null,
    "requirements": [
      {
        "name": "x11",
        "default_formula": null,
        "cask": "xquartz",
        "download": "https://xquartz.macosforge.org"
      }
    ],
    "options": [
      {
        "option": "--with-fftw",
        "description": "Compile with FFTW support"
      },
      {
        "option": "--with-hdri",
        "description": "Compile with HDRI support"
      },
      {
        "option": "--with-jp2",
        "description": "Compile with Jpeg2000 support"
      },
      {
        "option": "--with-openmp",
        "description": "Compile with OpenMP support"
      },
      {
        "option": "--with-perl",
        "description": "enable build/install of PerlMagick"
      },
      {
        "option": "--with-quantum-depth-8",
        "description": "Compile with a quantum depth of 8 bit"
      },
      {
        "option": "--with-quantum-depth-16",
        "description": "Compile with a quantum depth of 16 bit"
      },
      {
        "option": "--with-quantum-depth-32",
        "description": "Compile with a quantum depth of 32 bit"
      },
      {
        "option": "--without-opencl",
        "description": "Disable OpenCL"
      },
      {
        "option": "--without-magick-plus-plus",
        "description": "disable build/install of Magick++"
      },
      {
        "option": "--without-jpeg",
        "description": "Build without jpeg support"
      },
      {
        "option": "--without-libpng",
        "description": "Build without libpng support"
      },
      {
        "option": "--without-libtiff",
        "description": "Build without libtiff support"
      },
      {
        "option": "--without-freetype",
        "description": "Build without freetype support"
      },
      {
        "option": "--with-x11",
        "description": "Build with x11 support"
      },
      {
        "option": "--with-fontconfig",
        "description": "Build with fontconfig support"
      },
      {
        "option": "--with-little-cms",
        "description": "Build with little-cms support"
      },
      {
        "option": "--with-little-cms2",
        "description": "Build with little-cms2 support"
      },
      {
        "option": "--with-libwmf",
        "description": "Build with libwmf support"
      },
      {
        "option": "--with-librsvg",
        "description": "Build with librsvg support"
      },
      {
        "option": "--with-liblqr",
        "description": "Build with liblqr support"
      },
      {
        "option": "--with-openexr",
        "description": "Build with openexr support"
      },
      {
        "option": "--with-ghostscript",
        "description": "Build with ghostscript support"
      },
      {
        "option": "--with-webp",
        "description": "Build with webp support"
      },
      {
        "option": "--with-pango",
        "description": "Build with pango support"
      }
    ],
    "bottle": {
      "stable": {
        "revision": 0,
        "cellar": "/usr/local/Cellar",
        "prefix": "/usr/local",
        "root_url": "https://homebrew.bintray.com/bottles",
        "files": {
          "el_capitan": {
            "url": "https://homebrew.bintray.com/bottles/imagemagick-6.9.2-3.el_capitan.bottle.tar.gz",
            "sha256": "cd5edb53eae0271771df4a77a401a50e973b200ae875a04ef6a3f4d467ca2ef4"
          },
          "yosemite": {
            "url": "https://homebrew.bintray.com/bottles/imagemagick-6.9.2-3.yosemite.bottle.tar.gz",
            "sha256": "fbe139e4d7b540ce03fcde6a7735d9e79ed8652827cd7c877e551abcf804a494"
          },
          "mavericks": {
            "url": "https://homebrew.bintray.com/bottles/imagemagick-6.9.2-3.mavericks.bottle.tar.gz",
            "sha256": "99f2f95739d3ee11535fea62440f1608ce0ee1ef22bda2f878353360ab45e9cc"
          }
        }
      }
    }
  }
]

Original Answer

So you want the bottled packages which are not built from source.

# List all installed packages
for p in $(brew list); do
   # Get info about this particular one...
   # ... if bottled and not from source, print first line
   brew info $p | awk '/bottled/{p=$0} /Built from source/{p=""} END{if(length(p))print p}'
done

If you don't have too many packages installed, you may get away with this:

brew info $(brew list) | awk ...
like image 26
Mark Setchell Avatar answered Apr 01 '23 00:04

Mark Setchell