我最近将Mac OS X升级为优胜美地,我想确保我目前安装的每个包都是Yosemite瓶。
如何列出已安装的瓶子及其操作系统版本,以便最终卸载/安装它们?
编辑点击字符串“bottled”将无法正常工作,因为如果有一个瓶子可用于包,它仍然存在,但您仍然可以从源代码编译。例如,我刚刚从源代码构建了yasm,brew info yasm
返回:
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
[...]
答案 0 :(得分:2)
列出所有瓶装公式的最快方法是直接query brew info --json
的JSON输出(这需要jq
):
brew info --json=v1 --installed | jq -r "map(select(.installed[].poured_from_bottle) | .name) | unique | .[]"
在这里,brew info --json=v1 --installed
为所有已安装的公式提供JSON格式的信息。 jq
处理此操作(将其不带参数用于美化输出)。 select(.installed[].poured_from_bottle)
选择至少安装了一个瓶装版本的每个公式,map(... | .name)
返回关联的名称。 | unique
确保在安装了多个瓶装版本的情况下,公式名称仅返回一次,| .[]
将返回的名称数组分成一个列表,每个列表在单独的行中,并且{ {1}}去除JSON输出中的引号,留下可以传递给其他Shell命令的格式。
每次都要记住这有点复杂,但是您可以将此命令放入shell脚本中:
-r
将其命名为#!/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
,使其可执行(brew-bottled
)并将其放置在路径中的某个位置(例如chmod a+x brew-bottled
)。现在,您可以将其与/usr/local/bin
一起称为external command,以列出您的瓶装公式。 (作为额外的奖励,brew bottled
开关将包含版本信息,类似于--versions
,包括相同公式的多个瓶装版本。)
因此,如果您想从源代码中重建所有瓶装公式,则可以通过brew list --versions
将其通过管道传递给
xargs
(离开brew bottled | xargs brew reinstall -s
可以简单地重新安装当前的OS瓶。)
不幸的是,似乎无法确定当前安装了哪个macOS版本的瓶子,因此您可以肯定地重新安装所有瓶装公式。
答案 1 :(得分:1)
更新了答案
INSTALL_RECEIPT.json
内的每个homebrew
包中似乎都有/usr/local/Cellar
,例如这适用于OpenCV
/usr/local/Cellar/opencv/2.4.12/INSTALL_RECEIPT.json
它是标准的JSON,因此您可以像这样解析它而无需其他工具:
python -mjson.tool /usr/local/Cellar/opencv/2.4.12/INSTALL_RECEIPT.json
你得到了这个 - 这可能有助于你的事业......也许。
{
"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": []
}
您还可以以JSON格式获取brew info
命令的输出,例如:
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"
}
}
}
}
}
]
原始答案
所以你想要的是不是从源头构建的瓶装包装。
# 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
如果您没有安装太多软件包,您可能会放弃:
brew info $(brew list) | awk ...