brew: MacOS的包管理工具

这里写图片描述
brew是MacOS上的包管理工具,像RHEL/CentOS上的yum或者Ubuntu上的apt-get一样,MacOS上使用brew也可以非常容易进行包的管理。

概要信息

项目 说明
官方网站 https://brew.sh
开源/闭源 开源
License类别 BSD 2-Clause “Simplified” License
代码管理地址 https://github.com/Homebrew/brew
开发语言 Ruby
支持平台 MacOS
当前版本 1.6.9 (2018/06/18)

事前确认

因为brew是ruby开发的,需要使用确认ruby已经安装,缺省状况下是已经安装的。

liumiaocn:~ liumiao$ which ruby
/usr/bin/ruby
liumiaocn:~ liumiao$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
liumiaocn:~ liumiao$ 

安装命令

具体的安装脚本在raw.githubusercontent.com已有,使用如下命令即可安装

安装命令:ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

安装日志

liumiaocn:~ liumiao$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their owner set to liumiao:
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their group set to admin:
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man3
/usr/local/share/man/man5
/usr/local/share/man/man7

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> /usr/bin/sudo /usr/sbin/chown liumiao /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7
==> Downloading and installing Homebrew...
remote: Counting objects: 103258, done.
remote: Total 103258 (delta 0), reused 0 (delta 0), pack-reused 103257
Receiving objects: 100% (103258/103258), 23.47 MiB | 22.00 KiB/s, done.
Resolving deltas: 100% (75270/75270), done.
From https://github.com/Homebrew/brew
 * [new branch]          master     -> origin/master
...省略
 * [new tag]             1.6.9      -> 1.6.9
HEAD is now at 25542d739 Merge pull request #4316 from reitermarkus/merge-search
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': Could not resolve host: github.com
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core
Failed during: /usr/local/bin/brew update --force
liumiaocn:~ liumiao$

由于网络等的问题,往往容易出错,再次执行:

liumiaocn:~ liumiao$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
HEAD is now at 25542d739 Merge pull request #4316 from reitermarkus/merge-search
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4788, done.
remote: Compressing objects: 100% (4562/4562), done.
remote: Total 4788 (delta 56), reused 1038 (delta 38), pack-reused 0
Receiving objects: 100% (4788/4788), 3.88 MiB | 45.00 KiB/s, done.
Resolving deltas: 100% (56/56), done.
Tapped 4576 formulae (4,829 files, 12.2MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/liumiao/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh
liumiaocn:~ liumiao$ 

版本确认

liumiaocn:~ liumiao$ brew -v
Homebrew 1.6.9
Homebrew/homebrew-core (git revision cf4d; last commit 2018-06-19)
liumiaocn:~ liumiao$

常见操作

使用brew可以进行包的查询/安装/卸载等常见操作:

子命令 说明
info 确认包的安装状况
install 安装包
uninstall 卸载包
update 更新包
list 确认已经安装的包的状况
doctor 检测冲突

使用例

安装wget

比如使用brew install wget进行wget的安装

liumiaocn:~ liumiao$ brew install wget
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
blackbox              heroku                libdazzle             neofetch              packmol               pandoc-crossref
hadolint              jsonrpc-glib          lmod                  openjazz              paket                 rocksdb

==> Installing dependencies for wget: gettext, libunistring, libidn2, openssl
==> Installing wget dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.8.1.high_sierra.bottle.tar.gz

curl: (6) Could not resolve host: akamai.bintray.com
Error: Failed to download resource "gettext"
Download failed: https://homebrew.bintray.com/bottles/gettext-0.19.8.1.high_sierra.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Downloading https://ftp.gnu.org/gnu/gettext/gettext-0.19.8.1.tar.xz
######################################################################## 100.0%
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/gettext/0.19.8.1 --with-included-gettext --with-included-glib --with-
==> make
==> make install
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/gettext/lib
    CPPFLAGS: -I/usr/local/opt/gettext/include

==> Summary
��  /usr/local/Cellar/gettext/0.19.8.1: 1,935 files, 16.9MB, built in 8 minutes 10 seconds
==> Installing wget dependency: libunistring
==> Downloading https://homebrew.bintray.com/bottles/libunistring-0.9.10.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libunistring-0.9.10.high_sierra.bottle.tar.gz
��  /usr/local/Cellar/libunistring/0.9.10: 54 files, 4.4MB
==> Installing wget dependency: libidn2
==> Downloading https://homebrew.bintray.com/bottles/libidn2-2.0.5.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libidn2-2.0.5.high_sierra.bottle.tar.gz
��  /usr/local/Cellar/libidn2/2.0.5: 68 files, 668.6KB
==> Installing wget dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_2.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2o_2.high_sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
��  /usr/local/Cellar/openssl/1.0.2o_2: 1,792 files, 12.3MB
==> Installing wget
==> Downloading https://homebrew.bintray.com/bottles/wget-1.19.5.high_sierra.bottle.tar.gz

curl: (6) Could not resolve host: akamai.bintray.com
Error: Failed to download resource "wget"
Download failed: https://homebrew.bintray.com/bottles/wget-1.19.5.high_sierra.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==> Installing dependencies for wget: pkg-config
==> Installing wget dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2.high_sierra.bottle.tar.gz
��  /usr/local/Cellar/pkg-config/0.29.2: 11 files, 627.2KB
==> Downloading https://ftp.gnu.org/gnu/wget/wget-1.19.5.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/wget/1.19.5 --sysconfdir=/usr/local/etc --with-ssl=openssl --with-libssl-prefix=/usr/local/o
==> make install
��  /usr/local/Cellar/wget/1.19.5: 49 files, 3.7MB, built in 2 minutes 27 seconds
liumiaocn:~ liumiao$

确认已安装的包

liumiaocn:~ liumiao$ brew list
gdbm        jpeg        libpng      libunistring    pkg-config  readline    wget        wxpython
gettext     libidn2     libtiff     openssl     python@2    sqlite      wxmac
liumiaocn:~ liumiao$

确认wget包的详细信息

liumiaocn:~ liumiao$ brew info wget
wget: stable 1.19.5 (bottled), HEAD
Internet file retriever
https://www.gnu.org/software/wget/
/usr/local/Cellar/wget/1.19.5 (49 files, 3.7MB) *
  Built from source on 2018-06-19 at 14:47:58
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/wget.rb
==> Dependencies
Build: pkg-config ✔
Required: libidn2 ✔, openssl ✔
Optional: pcre ✘, libmetalink ✘, gpgme ✘
==> Options
--with-debug
    Build with debug support
--with-gpgme
    Build with gpgme support
--with-libmetalink
    Build with libmetalink support
--with-pcre
    Build with pcre support
--HEAD
    Install HEAD version
liumiaocn:~ liumiao$

猜你喜欢

转载自blog.csdn.net/liumiaocn/article/details/80738838