mac 安装 homebrew
转自:乔一亖
地址:https://www.cnblogs.com/joyce33/p/13376752.html
感谢作者的辛苦付出,尊重版权,从我做起。
Homebrew 是什么
Homebrew是 mac的包管理器,仅需执行相应的命令,就能下载安装需要的软件包,可以省掉自己去下载、解压、拖拽(安装)等繁琐的步骤。 比如安装服务器 nginx,打开终端执行以下命令即可安装:
brew install nginx
Homebrew 官方文档 https://brew.sh/
安装方法
brew 镜像安装脚本(亲测最快速最有效)
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
注:最后出现 Installation successful! 或者 Checking out files: 100% (5392/5392), done. 说明安装成功。
Homebrew安装完为何需要配置
前面已经提到,Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。
这里用的是由中科大负责托管维护的 Homebrew 镜像。其中,前两个为必须配置的项目,后两个可按需配置。
1.必备设置
-
替换 brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
-
替换 homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
2.按需设置
-
替换 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
-
替换homebrew-bottles:
-
首先要先区分你的mac用哪种终端工具,如果是 bash,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile -
若是 zsh,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
-
注:Homebrew 主要由四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它们对应的功能如下:
组成 功能
Homebrew 源代码仓库
homebrew-core Homebrew 核心源
homebrew-cask 提供macos应用和大型二进制文件的安装
homebrew-bottles 预编译二进制软件包
Homebrew 基本用法有哪些
// 查询:
brew search 软件名
// 安装:
brew install 软件名
// 卸载:
brew uninstall 软件名
// 更新 Homebrew:
brew update
// 查看 Homebrew 配置信息:
brew config