安装Homebrew的目的

  • Homebrew installs the stuff you need that Apple didn’t.

  • Homebrew installs packages to their own directory and then symlinks their files into /usr/local.

  • Homebrew won’t install files outside its prefix, and you can place a Homebrew installation wherever you like.

一言以蔽之,Homebrew可以方便的安装、升级、卸载各类package,而且都是在它自己的目录下,不会影响到系统的全局设置。

我主要将其用于安装pyenv。

安装要求

  • An Intel CPU 1

  • OS X 10.5 or higher 2

  • Command Line Tools for Xcode:
    xcode-select –install, https://developer.apple.com/downloads or Xcode

    注意:如果系统中没有Command Line Tools for Xcode,安装脚本会自动进行安装

  • A Bourne-compatible shell for installation (e.g. bash or zsh)

安装过程

  • ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”

    直接执行上述命令即可,不需要sudo权限,执行过程中会自动调用sudo请求输入密码

    Alexs-Mac:~ alex$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    ==> This script will install:
    /usr/local/bin/brew
    /usr/local/Library/...
    /usr/local/share/man/man1/brew.1
    
    Press RETURN to continue or any other key to abort
    ==> /usr/bin/sudo /bin/mkdir /usr/local
    
    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type "man sudo" for more information.
    
    To proceed, enter your password, or type Ctrl-C to abort.
    
    Password:
    ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
    ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
    ==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
    ==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
    ==> Installing the Command Line Tools (expect a GUI popup):
    ==> /usr/bin/sudo /usr/bin/xcode-select --install
    xcode-select: note: install requested for command line developer tools
    Press any key when the installation has completed.
    

    此时,会出现安装xcode command line developer tools的对话框:

    The "xcode-select" command requires the command line developer tools.
    Would you like to install the tools now?
    
    Choose Install to continue.
    Choose Get Xcode to install Xcode and the command line developer tools from the App Store.
    
    对话框下面有这3个按钮:
    Get Xcode   Not Now     Install
    

    点击Install按钮后开始进行安装,安装完后要立即开始接下来的后续安装操作,
    否则Git下载会很慢,很不稳定,极有可能会出现下面的提示,从而安装失败:

    ==> Downloading and installing Homebrew...
    fatal: unable to access 'https://github.com/Homebrew/homebrew/': transfer closed with outstanding read data remaining
    Failed during: git fetch origin master:refs/remotes/origin/master -n
    

    安装失败后不要着急,使用Contrl-C结束后,然后执行下面命令进行清理:

    Alexs-Mac:~ alex$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
    -bash: brew: command not found
    

    清理完成后再继续使用之前的命令重新安装一下:

    Alexs-Mac:~ alex$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    ==> This script will install:
    /usr/local/bin/brew
    /usr/local/Library/...
    /usr/local/share/man/man1/brew.1
    
    Press RETURN to continue or any other key to abort
    ==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
    Password:
    ==> Downloading and installing Homebrew...
    remote: Counting objects: 166499, done.
    remote: Compressing objects: 100% (46784/46784), done.
    remote: Total 166499 (delta 118620), reused 166468 (delta 118599)
    Receiving objects: 100% (166499/166499), 31.57 MiB | 12.00 KiB/s, done.
    Resolving deltas: 100% (118620/118620), done.
    From https://github.com/Homebrew/homebrew
     * [new branch]      master     -> origin/master
    HEAD is now at b8b3a30 glib-networking 2.40.1
    ==> Installation successful!
    You should run `brew doctor' *before* you install anything.
    Now type: brew help
    
  • 安装完后可以使用brew doctor命令先检查一下,看是否已经完全安装正确了

    Alexs-Mac:~ alex$ brew doctor
    Your system is ready to brew.
    

参考