mac下更新brew国内源

一.换源
方法一:
1.卸载
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
2.安装
方法一:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
方法二:
把官网给的脚本拿下来 
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
更改脚本中的资源链接,替换成中国科学技术大学的镜像:
BREW_REPO = “https://github.com/Homebrew/brew“.freeze 
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze 
更改为这两句 
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git “.freeze 
CORE_TAP_REPO = “https://mirrors.ustc.edu.cn/homebrew-core.git“.freeze 
执行脚本
/usr/bin/ruby brew_install
!在安装有坑,ping https://github.com试试。
3.替换成国内源
替换homebrew默认源
cd "$(brew --repo)"
/usr/local/Homebrew
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替换homebrew-core源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
替换homebrew-cask源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
4.设置 bintray镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
5.更新
brew update
6.踩坑
6.1.
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': transfer closed with outstanding read data remaining
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-core /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1` exited with 128.
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/core` exited with 1.
Failed during: /usr/local/bin/brew update --force
分析:
网络问题,手工下载。
创建目录:
cd "$(brew --repo)"
cd Library/Taps/
mkdir homebrew
cd homebrew/
mkdir homebrew-core
cd homebrew-core/
开始clone
git clone git://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
6.2.
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
-bash: cd: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask: No such file or directory
$ brew cask install atom
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'…
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/': transfer closed with outstanding read data remaining
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-cask /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask —depth=1` exited with 128.
分析:
故障原因和上面一样,处理方式也一样就可以了。
创建目录:
mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
开始clone
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

二.常用命令
brew search <package_name> # 搜索
brew install <package_name> # 安装一个软件
brew uninstall <package_name> # 卸载一个软件
brew update # 从服务器上拉取,并更新本地 brew 的包目录
brew upgrade <package_name> # 更新一个软件
brew upgrade # 更新全部已安装软件
brew outdated # 查看你的软件中哪些有新版本可用
brew cleanup # 清理老版本。使用 `-n` 参数,不会真正执行,只是打印出真正运行时会做什么。
brew list --versions # 查看你安装过的包列表(包括版本号)
brew link <package_name> # 将软件的当前最新版本软链到`/usr/local`目录下
brew unlink <package_name> # 将软件在`/usr/local`目录下的软链接删除。
brew info # 显示软件的信息
brew deps # 显示包依赖
brew doctor # 检查brew软件的安装是否正常
brew prune # 移除链接失效的文件
brew --cache # 打印下载软件的缓存路径
brew --config # 打印brew的配置信息
brew --env # 打印brew的环境信息
brew --prefix # 打印prefix的路径(通常是/usr/local/)
brew --prefix [formula] # 指出formula安装位置

参考:
Homebrew 中文主页
https://brew.sh/index_zh-cn.html
Homebrew Bottles 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-bottles.html
Homebrew Cask 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-cask.git.html
Homebrew Core 源使用帮助
http://mirrors.ustc.edu.cn/help/homebrew-core.git.html

posted on 2019-07-27 13:29  candyjihui  阅读(5993)  评论(0编辑  收藏  举报

导航