====== MACOS HOME-BREW 包管理器 ====== HOME BREW 是 MAC 或者 Linux 上非常流行的(特别是MACOS上)第三方软件包管理器 ===== HOME BREW 部件 ===== HOME BREW 部件: * homebrew-core --核心软件库 * brew -- 源代码仓库 * homebrew-cask --大型软件库 * homebrew-bottle --预编译二进制库 该包管理器相关数据和安装的软件包均在:/opt/homebrew 目录下 ===== HOME BREW 依赖项 ===== * RUBY 脚本环境,MAC系统似乎已经自带了 * CURL 用于获取互联网软件包或者源码包,MAC系统已经自带了 * CLANG 用于编译,这个可能要安装,应该安装开发工具就行了,命令 xcode-select * GIT 用于管理源码包及软件自身的源,MAC好像没自带,使用命令 xcode-select 安装 ===== HOME BREW 用到的环境变量 ===== HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_REPOSITORY=/opt/homebrew INFOPATH=/opt/homebrew/share/info: 换源的时候重新设置环境变量并用 export 导出即可,参见软件源更换的相关部分 ====== 安装 HOME BREW ====== 注意挂上互联网工具 export ALL_PROXY=socks5h://127.0.0.1:10808 export HTTP_PROXY=http://127.0.0.1:10809 export HTTPS_PROXY=http://127.0.0.1:10809 一般来说设置 ALL_PROXY 也就够了 一句话安装脚本 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 可以注意到安装需要 ruby 的支持,这个软件在 MAC 上已经有了,但是其他 *NIX 发行版上可能未必有,需要安装 ====== 包管理 ====== ===== 常用命令 ===== * 安装源码包: brew install PKG * 安装软件包: brew install PKG --cask #较早版本使用的 brew cask install * 删除软件包:brew uninstall PKG --cask #较早版本使用的 brew cask uninstall * 删除源码包:brew uninstall PKG * 查看已安装软件:brew list [--cask] * 升级软件包: brew upgrade PKG-NAME 有源码包和编译包,使用 ''brew install PKG-NAME'' 是源码包,使用 ''brew install PKG-NAME --cask'' 安装的是二进制包。一般不用管,只要使用Search搜索了出来,系统会提示软件在哪个 channel 里面,如果在 CASK 里面,安装时就使用 ''--cask'' 选项。 因为直接从GITHUB取数据,并且直接使用GITHUB REPO URL,所以不支持中文名,一些中文的软件可能要麻烦一点,可以参考:[[https://github.com/cactusnix/brew-apps|这个仓库]]查找对应中英文名称。 ===== 安装特定版本 ===== 四个板斧 * 搜索软件包: brew search Keyword * 获取安装地址(一个可执行的 *.rb 脚本文件):brew info PKG-NAME 查看 ''FROM:'' 部分 * 用浏览器打开那个.rb文件地址,点击右侧 ''History'' 并下载想要安装的历史版本的 .rb 文件,保存为:PKGNAME-$(VERSION).rb * 使用 brew 安装 rb 文件: brew install /path/to/PKGNAME-$(VERSION).rb 注:如果之前已经安装了,系统会提示你进行移除或者卸载 ====== HOME BREW 本身的管理 ====== HOME BREW 安装的软件包保存在 ''/opt/home-brew'' 目录下 ===== HOME BREW 升级与重置 ===== * 升级与重置brew缓存数据库:brew update [--auto-update] * 查看特定命令的帮助: brew help COMMAND ===== 更换软件源 ===== 这个是可选项,有正常的互联网代理的话最好就不更换了。 HOME BREW 的软件源完全是依赖 GIT 来管理的,它会通过GIT仓库和远端源进行映射来设置软件的下载地址,BREW 使用的 repo HOME: brew --repo HOME-CORE: brew --repo homebrew/core HOME-CASK: brew --repo homebrew/cask 查看软件源信息 brew config ==== 阿里源 ==== # 查看 brew.git 当前源 $ cd "$(brew --repo)" && git remote -v origin https://github.com/Homebrew/brew.git (fetch) origin https://github.com/Homebrew/brew.git (push) # 查看 homebrew-core.git 当前源 $ cd "$(brew --repo homebrew/core)" && git remote -v origin https://github.com/Homebrew/homebrew-core.git (fetch) origin https://github.com/Homebrew/homebrew-core.git (push) # 修改 brew.git 为阿里源 $ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git # 修改 homebrew-core.git 为阿里源 $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git # zsh 替换 brew bintray 镜像 $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc $ source ~/.zshrc # bash 替换 brew bintray 镜像 $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile $ source ~/.bash_profile # 刷新源 $ brew update ==== 清华源 ==== # 替换各个源 $ 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 # zsh 替换 brew bintray 镜像 $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc $ source ~/.zshrc # bash 替换 brew bintray 镜像 $ 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.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 # zsh 替换 brew bintray 镜像 $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc $ source ~/.zshrc # bash 替换 brew bintray 镜像 $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile $ source ~/.bash_profile # 刷新源 $ brew update ==== 官方源 ==== # 重置 brew.git 为官方源 $ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git # 重置 homebrew-core.git 为官方源 $ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git # 重置 homebrew-cask.git 为官方源 $ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask # zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 $ vi ~/.zshrc # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx # bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 $ vi ~/.bash_profile # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx # 刷新源 $ brew update ====== 国内安装HOME BREW ====== https://brew.sh/zh-cn/