侧边栏壁纸
博主头像
Wood Chen博主等级

独唱独酬,独行独坐还独卧

  • 累计撰写 233 篇文章
  • 累计创建 166 个标签
  • 累计收到 9 条评论

目 录CONTENT

文章目录

homebrew安装软件失败,fatal: not in a git directory Error: Command failed with exit 128: git

wood
2023-04-17 / 0 评论 / 0 点赞 / 23 阅读 / 17141 字

本次安装碰到了以下问题:

  1. Git 子模块(submodule)没有初始化或更新
  2. 当前用户对 Homebrew 核心源代码的拥有权不正确
  3. 某些文件冲突而导致的。在这种情况下,Homebrew 无法将 Node.js 安装到 /usr/local 目录中,并给出了一些可能存在冲突的文件列表
  4. 目录 /usr/local/share/doc/node 不可写

Q:

brew install node
==> Fetching dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Fetching brotli

......

==> Installing dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Installing node dependency: brotli
fatal: not in a git directory
Error: Command failed with exit 128: git

A:

根据命令行输出的信息,看起来是在执行 brew install node 命令时出现了错误。具体来说,似乎是在安装依赖项 brotli 时发生了错误,并给出了一个类似于 Git 错误的消息:fatal: not in a git directory

这个错误可能是由于 Homebrew(包管理器)正在尝试从 GitHub 上下载 brotli 的源代码,但是 Git 报告说当前目录不在 Git 仓库中,因此无法进行操作。这可能是因为 Git 子模块(submodule)没有初始化或更新所导致的。

要解决这个问题,可以尝试运行以下命令:

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git submodule update --init --recursive

这将进入 Homebrew 核心源代码的目录,并强制 Git 初始化和更新所有子模块。然后重新运行 brew install node 命令,应该就可以正常安装 Node.js 了。

Q

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core  git submodule update --init --recursive
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

A

根据命令行输出,运行 git submodule update --init --recursive 命令时,Git 报告了一个 "dubious ownership" 错误。这个错误通常是由于当前用户对 Homebrew 核心源代码的拥有权不正确所导致的。

要修复这个问题,按照 Git 给出的建议,可以运行以下命令:

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

这将为 Git 添加一个 "safe directory" 的例外,以允许当前用户在 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core 目录下执行 Git 操作。

然后再次尝试运行 git submodule update --init --recursive 命令,应该就可以正常更新所有子模块了。完成之后再重新运行 brew install node 命令,应该就可以正常安装 Node.js 了。

q

brew install node
==> Fetching dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Fetching brotli
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//brotli-1.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/96bb4df9c666e1609ccfdc2080e69778d67c387f2da3e7afc7941028197cb350--brotli-1.0.9.ventura.bottle.tar.gz
==> Fetching c-ares
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//c-ares-1.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/fbf38a853ddd40b168d30754efbc089c2982d92abefe71e5e1f49619df3e9357--c-ares-1.19.0.ventura.bottle.tar.gz
==> Fetching icu4c
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//icu4c-72.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/0465447acae6b8160cbb03f1b26c8a9d91ac933da0fab2007c523547d07c5e5f--icu4c-72.1.ventura.bottle.tar.gz
==> Fetching libnghttp2
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libnghttp
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/d885d219d024ae4f583aded82b55d1a66be653a6d3c655d6132281b480eab121--libnghttp2-1.52.0.ventura.bottle.tar.gz
==> Fetching libuv
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libuv-1.4
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/21f4c19762bebf3e8ad7fbca6d1ace817aa9a1e9b709ac9117414638b35a7f15--libuv-1.44.2.ventura.bottle.1.tar.gz
==> Fetching ca-certificates
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//ca-certif
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/9f9800e6ab85676885751e7dd738f512132b45c82bf81a4e11506e65572688aa--ca-certificates-2023-01-10.all.bottle.tar.gz
==> Fetching openssl@1.1
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//openssl%4
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/ef829b4ccf886aaddb24d8f83789074b4bfea1c8a207342967d89a706e38ff86--openssl@1.1-1.1.1t.ventura.bottle.tar.gz
==> Fetching node
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//node-19.9
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/92ace90a79a0730a7c74738b53bdeedb32e6ff58564610f0d3b4b915cf3d3365--node-19.9.0.ventura.bottle.tar.gz
==> Installing dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Installing node dependency: brotli
==> Pouring brotli-1.0.9.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/brotli/1.0.9: 25 files, 2.3MB
==> Installing node dependency: c-ares
==> Pouring c-ares-1.19.0.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/c-ares/1.19.0: 87 files, 655.6KB
==> Installing node dependency: icu4c
==> Pouring icu4c-72.1.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/icu4c/72.1: 263 files, 77.8MB
==> Installing node dependency: libnghttp2
==> Pouring libnghttp2-1.52.0.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/libnghttp2/1.52.0: 13 files, 715.3KB
==> Installing node dependency: libuv
==> Pouring libuv-1.44.2.ventura.bottle.1.tar.gz
🍺  /usr/local/Cellar/libuv/1.44.2: 51 files, 3.5MB
==> Installing node dependency: ca-certificates
==> Pouring ca-certificates-2023-01-10.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2023-01-10: 3 files, 216.8KB
==> Installing node dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1t.ventura.bottle.tar.gz
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##O#-#
🍺  /usr/local/Cellar/openssl@1.1/1.1.1t: 8,101 files, 18.5MB
==> Installing node
==> Pouring node-19.9.0.ventura.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
==> Summary
🍺  /usr/local/Cellar/node/19.9.0: 2,260 files, 56.3MB
==> Running `brew cleanup node`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

a

根据命令行输出,brew install node 命令已经成功安装了 Node.js 和相关依赖项。但是,在执行完最后一步 "Installing node" 后,出现了一个错误消息:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py

这个错误通常是由于某些文件冲突而导致的。在这种情况下,Homebrew 无法将 Node.js 安装到 /usr/local 目录中,并给出了一些可能存在冲突的文件列表。

为了解决这个问题,可以尝试运行以下命令来覆盖所有可能冲突的文件:

brew link --overwrite node

这将强制 Homebrew 覆盖任何与 Node.js 冲突的文件,并将其链接到 /usr/local 目录中。如果需要,也可以使用 brew link --overwrite --dry-run node 命令来查看将会被删除的文件列表。完成之后,可以再次运行 brew cleanup node 命令来清理安装时产生的临时文件。

现在,可以通过运行 node -v 命令来验证 Node.js 是否已成功安装。

q

 brew link --overwrite node
Linking /usr/local/Cellar/node/19.9.0...
Error: Could not symlink share/doc/node/gdbinit
/usr/local/share/doc/node is not writable.

a

根据命令行输出,运行 brew link --overwrite node 命令时出现了一个新的错误:Homebrew 无法链接 /usr/local/Cellar/node/19.9.0/share/doc/node/gdbinit 文件,因为目录 /usr/local/share/doc/node 不可写。

这个错误通常是由于当前用户没有写入 /usr/local 目录的权限所导致的。要解决此问题,可以尝试使用以下方法:

  1. 以管理员身份运行终端应用程序。要做到这一点,可以按下 Command + 空格键,打开 Spotlight 搜索框,然后输入 "Terminal" 并按下回车键。在终端窗口中,输入以下命令并按下回车键:

    sudo chown -R $(whoami) /usr/local/share

    这将更改 /usr/local/share 目录的所有者,以便您能够将文件和目录写入其中。

  2. 现在再次运行 brew link --overwrite node 命令,应该就可以成功安装 Node.js 了。如果还是遇到类似的错误,请尝试重启计算机,然后再次运行 brew link --overwrite node 命令。

完成之后,可以通过运行 node -v 命令来验证 Node.js 是否已成功安装。

完整的过程

brew install node
==> Fetching dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Fetching brotli
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//brotli-1.
######################################################################## 100.0%
==> Fetching c-ares
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//c-ares-1.
######################################################################## 100.0%
==> Fetching icu4c
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//icu4c-72.
######################################################################## 100.0%
==> Fetching libnghttp2
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libnghttp
######################################################################## 100.0%
==> Fetching libuv
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libuv-1.4
######################################################################## 100.0%
==> Fetching ca-certificates
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//ca-certif
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/9f9800e6ab85676885751e7dd738f512132b45c82bf81a4e11506e65572688aa--ca-certificates-2023-01-10.all.bottle.tar.gz
==> Fetching openssl@1.1
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//openssl%4
######################################################################## 100.0%
==> Fetching node
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//node-19.9
######################################################################## 100.0%
==> Installing dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Installing node dependency: brotli
fatal: not in a git directory
Error: Command failed with exit 128: git
 ✘ woodchen@wooddeMacBook-Pro  ~  cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
 woodchen@wooddeMacBook-Pro  /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core  git submodule update --init --recursive
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

    git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
 ✘ woodchen@wooddeMacBook-Pro  /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core  git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

 woodchen@wooddeMacBook-Pro  /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core   master ±  git submodule update --init --recursive
 
 brew install node
==> Fetching dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Fetching brotli
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//brotli-1.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/96bb4df9c666e1609ccfdc2080e69778d67c387f2da3e7afc7941028197cb350--brotli-1.0.9.ventura.bottle.tar.gz
==> Fetching c-ares
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//c-ares-1.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/fbf38a853ddd40b168d30754efbc089c2982d92abefe71e5e1f49619df3e9357--c-ares-1.19.0.ventura.bottle.tar.gz
==> Fetching icu4c
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//icu4c-72.
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/0465447acae6b8160cbb03f1b26c8a9d91ac933da0fab2007c523547d07c5e5f--icu4c-72.1.ventura.bottle.tar.gz
==> Fetching libnghttp2
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libnghttp
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/d885d219d024ae4f583aded82b55d1a66be653a6d3c655d6132281b480eab121--libnghttp2-1.52.0.ventura.bottle.tar.gz
==> Fetching libuv
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//libuv-1.4
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/21f4c19762bebf3e8ad7fbca6d1ace817aa9a1e9b709ac9117414638b35a7f15--libuv-1.44.2.ventura.bottle.1.tar.gz
==> Fetching ca-certificates
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//ca-certif
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/9f9800e6ab85676885751e7dd738f512132b45c82bf81a4e11506e65572688aa--ca-certificates-2023-01-10.all.bottle.tar.gz
==> Fetching openssl@1.1
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//openssl%4
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/ef829b4ccf886aaddb24d8f83789074b4bfea1c8a207342967d89a706e38ff86--openssl@1.1-1.1.1t.ventura.bottle.tar.gz
==> Fetching node
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles//node-19.9
Already downloaded: /Users/woodchen/Library/Caches/Homebrew/downloads/92ace90a79a0730a7c74738b53bdeedb32e6ff58564610f0d3b4b915cf3d3365--node-19.9.0.ventura.bottle.tar.gz
==> Installing dependencies for node: brotli, c-ares, icu4c, libnghttp2, libuv, ca-certificates and openssl@1.1
==> Installing node dependency: brotli
==> Pouring brotli-1.0.9.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/brotli/1.0.9: 25 files, 2.3MB
==> Installing node dependency: c-ares
==> Pouring c-ares-1.19.0.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/c-ares/1.19.0: 87 files, 655.6KB
==> Installing node dependency: icu4c
==> Pouring icu4c-72.1.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/icu4c/72.1: 263 files, 77.8MB
==> Installing node dependency: libnghttp2
==> Pouring libnghttp2-1.52.0.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/libnghttp2/1.52.0: 13 files, 715.3KB
==> Installing node dependency: libuv
==> Pouring libuv-1.44.2.ventura.bottle.1.tar.gz
🍺  /usr/local/Cellar/libuv/1.44.2: 51 files, 3.5MB
==> Installing node dependency: ca-certificates
==> Pouring ca-certificates-2023-01-10.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2023-01-10: 3 files, 216.8KB
==> Installing node dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1t.ventura.bottle.tar.gz
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##O#-#
🍺  /usr/local/Cellar/openssl@1.1/1.1.1t: 8,101 files, 18.5MB
==> Installing node
==> Pouring node-19.9.0.ventura.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
  rm '/usr/local/share/doc/node/gdbinit'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/share/doc/node/gdbinit
/usr/local/share/doc/node/lldb_commands.py
==> Summary
🍺  /usr/local/Cellar/node/19.9.0: 2,260 files, 56.3MB
==> Running `brew cleanup node`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
 ✘ woodchen@wooddeMacBook-Pro  ~  node -v
zsh: command not found: node
 ✘ woodchen@wooddeMacBook-Pro  ~  brew link --overwrite node
Linking /usr/local/Cellar/node/19.9.0...
Error: Could not symlink share/doc/node/gdbinit
/usr/local/share/doc/node is not writable.
 ✘ woodchen@wooddeMacBook-Pro  ~  sudo chown -R $(whoami) /usr/local/share
Password:
 woodchen@wooddeMacBook-Pro  ~  brew link --overwrite node
Linking /usr/local/Cellar/node/19.9.0... 6 symlinks created.
 woodchen@wooddeMacBook-Pro  ~  node -v
v19.9.0
 woodchen@wooddeMacBook-Pro  ~  npm -v
9.6.3
0

评论区