HomeBrew基础

安装 HomeBrew

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

改源

使用阿里源

1
2
3
4
5
6
7
8
9
10
11
# 替换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

使用回官方源

1
2
3
4
5
6
7
8
# 重置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

#删除zshrc HOMEBREW_BOTTLE_DOMAIN内容

基础命令

命令 说明
brew install 软件名 安装软件
brew uninstall 软件名 卸载软件
brew update 更新所有软件
brew upgrade 软件名 更新具体软件
brew search 软件名 搜索软件
brew list 显示已安装软件
brew outdated 查看那些已安装的程序需要更新
brew reps 显示包依赖
brew cleanup 清理不需要的版本极其安装包缓存
brew cleanup 软件名 清理不需要的某软件版本极其安装包缓存
brew services start 设置开机启动
brew services stop 设置开机不启动
brew services run 只运行不开机启动
brew doctor 验证

安装常用软件

安装 Telnet

1
2
$ brew install telnet
$ telnet ip port

常见问题

brew update报错

错误描述

1
2
3
4
5
6
7
8
Updating Homebrew...
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

warning: There are too many unreachable loose objects; run 'git prune' to remove them.

解决办法

1
2
3
4
$ cd "$(brew --repo)"
$ git prune && git gc
$ cd -
$ brew update

Unknown command: services

1
2
brew services run mongodb-community
Error: Unknown command: services

解决办法

1
$ brew update-reset
坚持原创技术分享,您的支持将鼓励我继续创作!
0%