Homebraw介绍
Homebrew 是 macOS 的套件管理工具,是高效下载软件的一种方法,相当于 Linux 下的 yum、apt-get 神器,用于下载存在依赖关系的软件包。通俗地说,Homebrew 是类似于 Mac App Store 的一个软件商店。通过 Homebrew 下载的软件都来自于官网,绝对放心软件的安全性。而且它尽可能地利用系统自带的各种库,使得软件包的编译时间大大缩短,基本上不会造成冗余。
Homebrew常用命令
# 查看brew版本
brew -v
# 帮助
brew -h / brew help
# 查看已安装的包
brew list
# 查询软件包
brew search [要找的软件]
# 安装软件
brew install [软件名字]
# 卸载软件
brew uninstall [软件名字]
# 更新软件
brew upgrade [软件名字]
# 查看需要更新的软件
brew outdated
# 查看软件信息
brew info [软件名字]
# 更新homebrew
brew update
# 查看可清理的旧版本包
brew cleanup -n
# 清理所有包的旧版本
brew cleanup
# 清理指定包的旧版本
brew cleanup [软件名字]
# 安装已经编译好的包
brew cask install [软件名字] / brew install --cask docker
# brew主要用来下载一些不带界面的命令行下的工具和第三方库来进行二次开发
# brew cask主要用来下载一些带界面的应用软件,下载好后会自动安装,并能在mac中直接运行使用
# 安装Homebrew
# 安装依赖工具 xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# 卸载Homebrew
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
# 查看 brew.git 当前源
cd "$(brew --repo)" && git remote -v
# 查看 homebrew-core.git 当前源
cd "$(brew --repo homebrew/core)" && git remote -v
## 切换 Homebrew 镜像源为清华镜像
# 替换brew.git:
cd "$(brew --repo)" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# zsh 替换homebrew-bottles镜像,Mac OS在10.15系统开始,默认的shell都换成了zsh
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
# 修改使其立即生效
source ~/.zshrc
# bash 替换homebrew-bottles镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
# 修改使其立即生效
source ~/.bash_profile
# 刷新源
brew update
# 更换源 -中科大
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc