macOS(OS X)安装与配置 Homebrew

  Homebrew 是 macOS 平台的软件包管理器,相当于 Linux 常用的 apt-get,zypper,pacman 等。

 

安装:

打开终端,逐条执行以下命令

首先需要安装依赖包 Xcode,弹出来的对话框请一路点击 OK,过程长短看网速。

xcode-select --install

然后安装 Homebrew,粘贴到终端里回车即可。(注意这是一整条命令,不同浏览方式可能被折行,务必完整复制)

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

最后执行这个命令,没有报错则可确认安装成功(一般输出是 "Your system is ready to brew.")。

brew doctor

这样海外和已经有系统全局代理设置的朋友们就可以直接使用 brew 命令安装软件了。

 

换源:

直接使用 Homebrew 还需要更改默认源,不然谁用谁想打人,原因你懂的。以下是将默认源替换为国内 USTC 源的方法。

替换核心软件仓库

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

替换 cask 软件仓库(提供 macOS 应用和大型二进制文件)

cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

替换 Bottles 源(Homebrew 预编译二进制软件包)

bash(默认 shell)用户:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

zsh 用户:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

 

基本用法:

假定操作对象为 wget,请替换为自己需要的软件包名

操作 命令
更新 Homebrew brew update
更新所有安装过的软件包 brew upgrade
更新指定的软件包 brew upgrade wget
查找软件包 brew search wget
安装软件包 brew install wget
卸载软件包 brew remove wget
列出已安装的软件包 brew list
查看软件包信息 brew info wget
列出软件包的依赖关系 brew deps wget
列出可以更新的软件包 brew outdated

参考:

Homebrew 中文主页

https://brew.sh/index_zh-cn.html

 Homebrew Bottles 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-bottles.html

 Homebrew Cask 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html

 Homebrew Core 源使用帮助

http://mirrors.ustc.edu.cn/help/homebrew-core.git.html

 

posted @ 2017-07-23 20:29  天上掉下的X  阅读(13926)  评论(1编辑  收藏  举报