Homebrew包管理器的安装教程和常用命令
更新:HHH   时间:2023-1-7


这篇文章主要讲解了“Homebrew包管理器的安装教程和常用命令”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Homebrew包管理器的安装教程和常用命令”吧!

Homebrew包管理器

[toc]

一、简介

Homebrew是Mac OS X下的一款软件包管理器, 相当于Linux下的yum、apt-get. 通过Homebrew可以方便的下载、安装应用, 不再需要亲自动手去搜索各种安装包.

注意:Homebrew与Mac OS X中的MacPorts包管理器不兼容, 如果已经安装MacPorts, 需先将其卸载.

二、安装

安装Xcode命令行工具

Homebrew包管理器依赖Xcode的命令行工具Command Line Tools (CLT) for Xcode, 可以通过两种方式来获取:

  • 只安装Xcode命令行工具, 在终端执行如下命令:

    xcode-select --install

  • 直接在AppStore中安装整个Xcode(如果有用Xcode做开发的话)

安装Homebrew

直接在终端中执行如下命令执行安装即可

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

安装结束后查看Homebrew版本信息

brew --version

三、替换Homebrew安装源

这里替换为清华大学开源软件镜像站的安装源, 直接在终端执行如如下命令即可:

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

如果需要替换二进制预编译包源的话, 可以执行如下命令:

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

source ~/.bash_profile

复原操作可以参考https://mirrors.tuna.tsinghua.edu.cn/help/homebrew

四、禁用自动更新

Homebrew在安装应用时, 默认情况下会自动更新所有应用, 需要等待很长时间的更新操作, 可以选择屏蔽自动更新:

echo 'export HOMEBREW_NO_AUTO_UPDATE=true' >> ~/.bash_profile

source ~/.bash_profile

五、安装brew-cask

brew-cask是一个Homebrew的增强工具, 用于下载安装Mac OS X的GUI应用的二进制预编译包(Chrome、sourcetree等客户端).

Github地址为: https://github.com/xyb/homebrew-cask-completion

brew-cask可以采用如下命令安装:

brew install homebrew/completions/brew-cask-completion

或者

brew tap homebrew/completions
brew install brew-cask-completion

六、常用命令

输入brew命令可以看到brew的常用用法, brew cask的用法与brew大体一致

Example usage:
brew search     搜索包
brew info       查看包信息
brew install    安装包
brew update     更新brew
brew upgrade    更新软件包
brew outdated   查看可用更新
brew uninstall  卸载应用包
brew list       已安装列表

brew config     查看配置信息
brew doctor     诊断

brew help       查看帮助信息

感谢各位的阅读,以上就是“Homebrew包管理器的安装教程和常用命令”的内容了,经过本文的学习后,相信大家对Homebrew包管理器的安装教程和常用命令这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是天达云,小编将为大家推送更多相关知识点的文章,欢迎关注!

返回大数据教程...