Write the Code. Change the World.

8月 12

介绍

Homebrew是Mac上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件。其类似于centos的yum,ubuntu的apt-get

安装

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

终端中执行下边命令。

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

然后会提示安装以及要创建等目录。回车,输入密码,将进行下载安装。

到最后,会提示安装完成。

HEAD is now at fb33acb Merge pull request #2624 from mistydemeo/use_python_flock
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4423, done.
remote: Compressing objects: 100% (4228/4228), done.
remote: Total 4423 (delta 37), reused 472 (delta 14), pack-reused 0
Receiving objects: 100% (4423/4423), 3.52 MiB | 53.00 KiB/s, done.
Resolving deltas: 100% (37/37), done.
Tapped 4227 formulae (4,466 files, 11.0MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/zhoulin/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:
  http://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    http://docs.brew.sh

Homebrew安装软件,你没法自定义安装位置。

命令

  1. 检查是否有冲突: brew doctor
  2. 查看版本: brew -v
  3. 查看目录: which brew
  4. 搜索: brew search xxx
  5. 查询: brew info xxx (主要看具体的信息,比如目前的版本,依赖,安装后注意事项等)
  6. 安装: brew install xxx
  7. 更新: brew update (更新Homebrew自己,并且使得接下来的两个操作有意义)
  8. 检查过时(是否有新版本): brew outdated 列出所有安装的软件里可以升级的那些
  9. 升级: brew upgrade 升级所有可以升级的软件
  10. 清理: brew cleanup 清理不需要的版本及其安装包缓存
  11. 查看包安装目录: brew config |grep HOMEBREW
  12. 卸载: brew uninstall xxx
  13. 列出所有的安装包: brew list -version
  14. 清理无效项: brew prune

  1. cd $(brew --repo)
  2. cd $(brew --prefix)
  3. cd $(brew --prefix php71)

镜像

在国内,用Homebrew下载安装软件,往往速度比较慢或无法下载安装。这时,需要使用Homebrew镜像源。它主要分两部分:gir repo(位于Github)和二进制bottles(位于bintray)。国内公认做的比较好的镜像有中科大镜像,清华镜像。设置步骤如下。

#替换brew.git
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

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

#设置bintray镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

#更新
brew update

如果想切换到官方源:

cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

中科大Homebrew镜像官网设置:
https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git
https://lug.ustc.edu.cn/wiki/mirrors/help/homebrew-bottles

清华Homebrew镜像官网设置:
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注