You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

macOS Sierra 10.12.6安装Homebrew遇ssh_exchange_identification超时错误求助

解决Homebrew安装时ssh_exchange_identification: read: Operation timed out错误

我之前也碰到过一模一样的问题,这个超时错误本质是SSH连接GitHub服务器时出了问题,不管是官方脚本还是直接克隆仓库都会踩坑,给你几个亲测有效的解决办法:

先复盘下你的报错场景

你尝试了两种安装方式都触发了相同错误:

  1. 运行官方安装脚本
    执行命令:

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

    终端报错输出:

    Donal-Mac-mini:~ mymac$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    ==> This script will install:
    /usr/local/bin/brew
    /usr/local/share/doc/homebrew
    /usr/local/share/man/man1/brew.1
    /usr/local/share/zsh/site-functions/_brew
    /usr/local/etc/bash_completion.d/brew
    /usr/local/Homebrew
    Press RETURN to continue or any other key to abort
    ==> Downloading and installing Homebrew...
    ssh_exchange_identification: read: Operation timed out
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights and the repository exists.
    Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
    Donal-Mac-mini:~ mymac$
    
  2. 直接克隆Homebrew仓库
    执行命令:

    git clone https://github.com/Homebrew/homebrew.git
    

    终端报错输出:

    Donal-Mac-mini:~ mymac$ git clone https://github.com/Homebrew/homebrew.git
    Cloning into 'homebrew'...
    ssh_exchange_identification: read: Operation timed out
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights and the repository exists.
    Donal-Mac-mini:~ mymac$
    

解决方案

1. 强制Git用HTTPS代替SSH连接GitHub

这个方法最省心,直接让所有GitHub仓库的SSH请求自动转成HTTPS,绕过SSH连接的超时问题:

git config --global url."https://github.com/".insteadOf git@github.com:

执行完这个命令后,重新运行Homebrew的安装脚本,基本就能正常拉取仓库了。

2. 排查网络/代理/防火墙干扰

如果方法1没用,大概率是网络环境的问题:

  • 如果你开了代理(不管是全局代理还是浏览器代理),先完全关闭再尝试安装;
  • 检查本地防火墙是否拦截了22端口(SSH默认端口)的出站请求,暂时关闭防火墙试试;
  • 切换网络环境,比如换成手机热点,排除本地运营商网络的限制。

3. 手动克隆+软链接安装

如果上面两种方法都不行,直接手动用HTTPS克隆Homebrew到指定目录:

# 克隆Homebrew核心仓库到/usr/local/Homebrew
git clone https://github.com/Homebrew/brew.git /usr/local/Homebrew
# 创建brew命令的软链接到系统可执行路径
ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew

完成后验证安装是否成功:

brew --version

内容的提问来源于stack exchange,提问作者McDonal_11

火山引擎 最新活动