Mac上安装brew及使用

做为一名mac小白,这两天在搭建开发环境:包括:nodejsfisphpapache2等,在此过程中了解到brew是mac下一款非常棒的软件包管理系统,特学习整理brew的安装和使用。

其实在Homebrew之前,最常见的就是MacPorts 跟 Fink了。

MacPorts有个原则,对于软件包之间的依赖,都在MacPorts内部解决(/opt/local),无论系统本身是否包含了需要的库,都不会加以利用。这使得MacPorts过分的庞大臃肿,导致系统出现大量软件包的冗余,占用不小的磁盘空间,同时稍大型一点的软件编译时间都会难以忍受。

而Homebrew的原则恰恰相反,它尽可能地利用系统自带的各种库,使得软件包的编译时间大为缩短;同时由于几乎不会造成冗余,软件包的管理也清晰、灵活了许多。Homebrew的另一个特点是使用Ruby定义软件包安装配置(叫做formula),定制非常简单。

下面就是一个formula示例:

{
  name: "ffmpeg",
  full_name: "ffmpeg",
  oldname: null,
  aliases: [
    "ffmpeg@4"
  ],
  versioned_formulae: [
    "ffmpeg@2.8"
  ],
  desc: "Play, record, convert, and stream audio and video",
  homepage: "https://ffmpeg.org/",
  versions: {
    stable: "4.1.4",
    devel: null,
    head: "HEAD",
    bottle: true
  },
  revision: 1,
  version_scheme: 0,
  bottle: {
    stable: {
      rebuild: 0,
      cellar: "/usr/local/Cellar",
      prefix: "/usr/local",
      root_url: "https://homebrew.bintray.com/bottles",
      files: {
        mojave: {
          url: "https://homebrew.bintray.com/bottles/ffmpeg-4.1.4_1.mojave.bottle.tar.gz",
          sha256: "1fff696effdf5cdea3feb1b2d022018c6dfe47b71de640a46adc4631cdeccf1e"
        },
        high_sierra: {
          url: "https://homebrew.bintray.com/bottles/ffmpeg-4.1.4_1.high_sierra.bottle.tar.gz",
          sha256: "d8e05c780e5e97dd8c4502e7cd31d0dc1d9e21734c22674deadab07609255339"
        },
        sierra: {
          url: "https://homebrew.bintray.com/bottles/ffmpeg-4.1.4_1.sierra.bottle.tar.gz",
          sha256: "df8763246c89635363a965811f322e8fa253dc3a39f0b5812024f3a79027ff7a"
        }
      }
    }
  },
  keg_only: false,
  bottle_disabled: false,
  options: [ ],
  build_dependencies: [
    "nasm",
    "pkg-config",
    "texi2html"
  ],
  dependencies: [
    "aom",
    "fontconfig",
    "freetype",
    "frei0r",
    "gnutls",
    "lame",
    "libass",
    "libbluray",
    "libsoxr",
    "libvorbis",
    "libvpx",
    "opencore-amr",
    "openjpeg",
    "opus",
    "rtmpdump",
    "rubberband",
    "sdl2",
    "snappy",
    "speex",
    "tesseract",
    "theora",
    "x264",
    "x265",
    "xvid",
    "xz"
  ],
  recommended_dependencies: [ ],
  optional_dependencies: [ ],
  requirements: [ ],
  conflicts_with: [ ],
  caveats: null,
  installed: [ ],
  linked_keg: null,
  pinned: false,
  outdated: false
}

Homebrew Formulae这个地址提供了brew所有包的列表。

安装brew

brew官网上已经给出了brew的安装方式,一条简单的ruby命令(mac默认已安装了ruby)即可:

另:建议安装之前先安装xcode,安装之后才能编译各种东西 貌似软件大小有2G左右

在mac终端输入如下命令:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

使用

安装完之后,执行如下命令

$ brew -v
Homebrew 2.1.8
Homebrew/homebrew-core (git revision 888b7; last commit 2019-07-24)
Homebrew/homebrew-cask (git revision 92227a; last commit 2019-07-24)

表示安装成功

brew -h

查看可用命令

$ brew -h
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA

Contributing:
  brew create [URL [--no-fetch]]
  brew edit [FORMULA...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh

brew update

Fetch the newest version of Homebrew and all formulae from GitHub using git(1)
and perform any necessary migrations.

更新brew

$ brew update
Updated 1 tap (homebrew/cask).
No changes to formulae.

brew search

搜索软件包 Usage: brew search [options] [text|/text/]

$ brew search git

brew info

查看软件包信息 Usage: brew info [options] [formula]

$ brew info git

brew install

安装软件包 Usage: brew install [options] formula

brew install git

brew uninstall

卸载软件包 Usage: brew uninstall, rm, remove [options] formula

$ brew uninstall git

brew upgrade

升级过期的软件包 Usage: brew upgrade [options] formula

$ brew upgrade git

brew list

列出所有已安装的软件包 Usage: brew list, ls [options]

$ brew list

brew cleanup

Remove stale lock files and outdated downloads for formulae and casks, and
remove old versions of installed formulae. If arguments are specified, only do
this for the specified formulae and casks.

删除软件包 brew cleanup [options] [formula|cask]

$ brew cleanup

brew outdated

查看哪些已安装包需要更新 Usage: brew outdated [options]

$ brew outdated

brew home

Open formula’s homepage in a browser. If no formula is provided, open Homebrew’s own homepage in a browser.

$ brew home git

brew deps

查看软件包依赖 Usage: brew deps [options] formula

$ brew deps git

brew unlink

删除软件包的符号链接 Usage: brew unlink [options] formula

$ brew unlink git

brew link

添加软件包符号链接 Usage: brew ln, link [options] formula

$ brew link git

brew pin

锁定软件包,防止自动升级软件包

$brew pin git

参考

brew官网

这篇文章目前没有评论。

回复

(必填项)

(必填项)

(可选)