美文网首页
成功解决macos 安装homebrew速度慢

成功解决macos 安装homebrew速度慢

作者: 琰雪儿 | 来源:发表于2019-12-28 00:04 被阅读0次

前言:网速好的使用官方安装命令Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

我开的科学上网大法,依然十几KB/S,这谁抗的住。时间久了就出现下面的错误。

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

网上有更新git的说法。git config --global http.postBuffer 524288000。亲测无效,遇见直接绕行。

现在说说如何解决速度慢导致的安装失败的问题。解决思路,使用国内镜像,比如:中科大,清华大学之类的。我这里使用中科大的镜像。

一、先获取官方install文件 命令如下:

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

获取insatll文件,并且命名为brew_install

二、利用macOS的快捷搜索command+空格,搜索brew_install。找到后直接打开。

BREW_REPO = "https://github.com/Homebrew/brew".freeze
改为:BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
我是最新版所以没有CORE_TAP_REPO,没有的不需要专门去增加。
如果有CORE_TAP_REPO
CORE_TAP_REPO = “https://github.com/Homebrew/homebrew-core“.freeze
也改为CORE_TAP_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git".freeze即可。

三、运行安装,命令如下。

/usr/bin/ruby brew_install

⚠️注意:代码会停留在

==> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

这个位置。不要慌张。⚠️关闭整个终端命令框,重新打开。
输入以下命令即可:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

四、将brew切换到国内镜像源

# 步骤一
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 步骤二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

#步骤三
brew update

注意这里需要等待一会,因为要更新资源。
更新完后使用brew update,brew install速度变快很多了,不会卡在那半天没动静,替换镜像完成。

复原方法
# 步骤一
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 步骤二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core

#步骤三
brew update

安装完成后使用以下命令进行诊断,不出错即为OK。

诊断homebrew
brew doctor

五、brew几个常用命令

查看homebrew版本
brew -v

查看已安装的包
brew list

安装包
brew install packageName

卸载包
brew uninstall packageName

查找包
brew search packageName

查看包信息
brew info packageName 

更新homebrew
brew update

诊断homebrew
brew doctor

查看帮助信息
brew -h

参考地址:
https://www.uedbox.com/post/57246/
https://segmentfault.com/a/1190000021360086

生活总会给你第二次机会叫明天

相关文章

网友评论

      本文标题:成功解决macos 安装homebrew速度慢

      本文链接:https://www.haomeiwen.com/subject/yjdjoctx.html