1、安装Homebrew
1.1、常规安装命令:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
很慢或者报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
1.2、国内安装
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
该脚本用了中科大镜像加速访问,仅修改仓库地址部分,不会产生安全隐患。 关于中科大所提供的 Homebrew 镜像服务 https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git
卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
2、配置
Homebrew通常用来下载软件的,但它在安装软件时非常慢。为了提升安装速度,需要更改 Homebrew 的安装源,将其替换成国内镜像。
替换 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
替换 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替换homebrew-bottles:
终端是 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
omebrew 主要由四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它们对应的功能如下:
组成 功能
Homebrew 源代码仓库
homebrew-core Homebrew 核心源
homebrew-cask 提供macos应用和大型二进制文件的安装
homebrew-bottles 预编译二进制软件包
3、Homebrew的使用
(1)安装软件:brew install 软件名,例如:brew install wget
(2)搜索软件:brew search 软件名
(3)卸载软件:brew uninstall 软件名
(4)更新软件:brew upgrade 软件名,例如:brew upgrade git
(5)查看使用brew已安装的软件列表:brew list
(6)查看软件信息:brew info /home 软件名,例如:brew info git/brew home git
(7)查看哪些已安装的程序需要更新:brew outdated
(8)查看配置:brew config
brew安装好之后可以使用上述的一些命令来测试一下是否安装成功,例如使用brew list来查看一下当前brew安装的软件列表
3.1、软件安装
如:安装go
brew install go
3.2、安装指定版本
3.2.1、查看软件包安装来源
brew info go
执行上述命令您会得到如下信息:
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
3.2.2、Github中查看rb文件历史提价(版本)信息
- 点击 History: 查看历史提交列表
- 查找 go: 1.2.15,并点击: 找到我们需要的版本
- 点击 View:查看当前版本下的go.rb完整文件
- 点击 Raw : 查看go.rb源文件,复制地址栏网址(这一步是不是不需要了,3中的网址应该也可以?我没有尝试)
3.2.3、安装
brew install https://.../go.rb(上面复制的网址)
3.3、卸载
查看安装列表
brew list
卸载
brew uninstall go
4、国内其他安装卸载方式
安装脚本:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
卸载脚本:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"