一、什么是homebrew
Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用关心各种依赖和文件路径的情况,十分方便快捷。官网
二、homebrew安装
1、终端运行命令(需要梯子)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2、镜像安装
1、下载
ARM版Homebrew需要安装在/opt/homebrew路径下:
2、设置环境变量:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/ycd/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
ps:查看终端类型
#终端类型根据执行命令echo $SHELL显示的结果:
/bin/bash => bash => .bash_profile
/bin/zsh => zsh => .zprofile
从macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认Shell,使用.zprofile,所以对应命令:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
如果是macOS Mojave 及更低版本,并且没有自己配置过zsh,使用.bash_profile:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"
3、卸载:
cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
三、homebrew的用途
- 查看Homebrew命令:brew help
- 安装任意包:brew install ,eg:brew install node
- 卸载任意包:brew uninstall ,eg:brew uninstall git
- 查询可用包:brew search
- 查询已安装包列表:brew list
- 查看任意包信息:brew info
- 更新Homebrew:brew update
- Homebrew帮助信息:brew -h
- 查看brew版本:brew -v
- 更新brew版本:brew update
- 整理重复语句:open ~/.zshrc -e、open ~/.bash_profile -e