Mac OS X系统下安装及配置Homebrew教程
有过Linux使用经验的朋友应该知道apt-get(Debian系)、yum(RHEL系)、pacman(ArchLinux,轻量级Linux)这些在线安装软件的套件。在Mac OS也有类似的,比较有名的是Macports、Homebrew。现在就来大致介绍Homebrew的安装、配置、使用方法。
(1)配置系统
现在的Mac OS X已经是一个全64位的系统,有时候我们很头疼地告知编译器把所有文件都编译为64位。通常默认系统PATH是/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin,我们可以稍微更改一下一包含到通过Homebrew安装的文件。需要更改.bash_profile:
$ vim ~/.bash_profile
改为如下:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
使之生效:
$ . ~/.bash_profile
(2)安装Xcode Command Line Tools
在App Store安装免费的Xcode。查看是否安装Xcode,输入一下命令:
1
$ xcode-select -p
如果出现以下提示,说明已经安装:
/Applications/Xcode.app/Contents/Developer
下载安装Xcode好后在终端输入以下命令,安装编译软件必备的Xcode Command Line Tools,它包含了GCC编译器。
$ xcode-select --install
在弹出的对话框中安装即可。
QQ20141024-1
QQ20141024-2
(3)安装Homebrew
其实非常简单,可以参照官网安装。由于系统已经自带了ruby,如下命令即可安装。
MacBook-Air:~ weiz$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/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
==> Downloading and installing Homebrew...
remote: Counting objects: 207648, done.
remote: Compressing objects: 100% (55804/55804), done.
remote: Total 207648 (delta 150671), reused 207632 (delta 150658)
Receiving objects: 100% (207648/207648), 43.68 MiB | 793.00 KiB/s, done.
Resolving deltas: 100% (150671/150671), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
HEAD is now at acff365 perl 5.20.1: Add keg_only :provided_by_osx
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started
安装软件很容易:
$ brew install bash-completion ssh-copy-id wget
查看软件信息,在列出的信息中也会详细提示如何配置安装的软件,非常有用:
$ brew info bash-completion
bash-completion: stable 1.3
http://bash-completion.alioth.debian.org/
/usr/local/Cellar/bash-completion/1.3 (188 files, 1.1M) *
Built from source
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/bash-completion.rb
==> Caveats
Add the following lines to your ~/.bash_profile:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
Homebrew's own bash completion script has been installed to
/usr/local/etc/bash_completion.d
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
其中bash-completion是一个非常有用的软件,能按两下tab就能提示更多软件命令。安提示的信息安装即可。
比较有用的命令如brew update、brew doctor等需要自己摸索。
以下是Homebrew经常使用的命令:
查找软件包:brew search wget
安装软件包:brew install wget
列出已安装的软件包:brew list
删除软件包:brew remove wget
查看软件包信息:brew info wget
列出软件包的依赖关系:brew deps wget
更新brew:brew update
列出过时的软件包(已安装但不是最新版本):brew outdated
更新过时的软件包(全部或指定):brew upgrade 或 brew upgrade wget