首页 Homebrew MacOS Homebrew常用命令

MacOS Homebrew常用命令

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。

1、Homebrew安装

打开Mac 终端,执行下面命令,等待完成即可。注:后面的执行代码均在终端完成。

//官方安装方式
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
//卸载
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

//使用中科大源安装
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
//卸载
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/uninstall.sh)"

2、查看brew版本


brew -v

3、搜索软件

命令格式:brew search 软件名。例如:

brew search nginx

4、安装软件

命令格式:brew install 软件名。例如:

brew install nginx

5、卸载软件

命令格式:brew uninstall 软件名。例如:

brew uninstall nginx

6、查看安装的软件列表


brew list

7、更新 brew


brew update

8、显示软件信息

命令格式:brew info 软件名。例如:

brew info nginx

9、显示包依赖

命令格式:brew deps 软件名。例如:

brew deps nginx

10、配置brew源

因某些不可抗力原因,国内访问官方源会出现速度慢或访问不了的原因,建议更换国内源

10.1查看镜像源信息


brew config

10.2切换 Homebrew 镜像源为中科大镜像源


# 替换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

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

# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

10.3切换Homebrew 镜像源为阿里镜像源


# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

10.4重置 Homebrew 镜像源


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

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

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

# 应用生效
brew update

# 删除.zshrc变量
vim  ~/.zshrc
# 删除如下变量
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

# 执行更新
source ~/.zshrc

12、官网地址

https://brew.sh/zh-cn/

关注本站微信公众号