一、安装HomeBrew
Homebrew是一款软件包管理工具,支持macOS和linux系统,拥有安装、卸载、更新、查看、搜索等功能。
1.1 官网安装方法
- 打开官网链接
- 按指引复制命令到终端进行安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
但执行以上操作后会出现以下错误:
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)"
方法二:直接修改脚本文件进行安装
- 通过以下资源获取
brew_install.rb
文件百度网盘链接:https://pan.baidu.com/s/1qX1Pfg4nhX_vZW5mGRJkqg 密码:309u
- 替换下载源,将以下代码注释掉
BREW_REPO = "https://github.com/Homebrew/brew".freeze
更改为中科大镜像源
# BREW_REPO = "https://github.com/Homebrew/brew".freeze BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
- 打开命令端,运行已修改的
brew_install.rb
脚本,Return后输入密码继续执行
以上方法执行期间可能会出现git失败,界面停留在以下位置:
==> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…
- 解决git失败方法:ctrl+c 中断任务,运行以下命令,手动clone
- 创建
homebrew-core
文件夹1.首先进入
homebrew
目录:cd "$(brew --repo)/Library/Taps/homebrew/"
2.创建
homebrew-core
文件夹mkdir homebrew-core
- 开始clone
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
正常运行会出现以下界面:
- 对应不同访问安装脚本的方法,重新执行上述命令(如果使用的是中科大镜像访问方法需在此步骤重新执行一次),安装成功则显示
Installation successful!
显示安装的软件
1.3 Homebrew换源
- 替换
homebrew
源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
- 替换
homebrew-core
源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.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
- 更新
brew
cd
brew update
Already up-to-date
二、安装HomeBrew-Cask
2.1 安装方法
方法一:利用国内源手动clone下载(推荐)
- 创建
homebrew-cask
文件夹1.进入
homebrew
目录:cd "$(brew --repo)/Library/Taps/homebrew/"
2.创建
homebrew-cask
文件夹mkdir homebrew-cask
- 开始clone
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
方法二:利用官网文件安装
- 从官网上下载
homebrew-cask-master.zip
压缩包,解压后将文件夹名改为homebrew-cask
- 然后将其拷贝放入
/usr/local/Homebrew/Library/Taps/homebrew
中,与homebrew-core
文件夹同级- 至此完成
homebrew-cask
安装
方法三:使用以下命令进行安装
brew install cask
注意:期间会有错误提示要求重装某些软件,根据指示操作就可以了。该方法安装比较麻烦
安装软件测试:成功安装
2.2 homebrew-cask换源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
cd
brew update
Already up-to-date
# 运行HomeBrew医生,查看警告文件
brew doctor
三、卸载HomeBrew
使用中科大镜像uninstall脚本卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
四、常用命令
brew常用命令
# 显示帮助
brew –help
# 安装软件
brew install pandoc
# 卸载软件
brew uninstall 软件名
# 搜索软件
brew search git
# 查看经安装软件列表
brew list
# 更新所有软件
brew update
# 更新某具体软件
brew upgrade git
#显示软件内容信息
brew info git
# 查看哪些已安装的程序需要更新
brew outdated
cask常用命令,大部分命令与brew命令的使用逻辑相同
#下载软件
brew cask install cakebrew
#卸载软件
brew cask uninstall skitch
参考文章
https://juejin.im/post/5c738bacf265da2deb6aaf97#comment
https://blog.csdn.net/zbc415766331/article/details/104128351
https://www.cnblogs.com/beyondmch/articles/8331478.html