Wood Chen

Homebrew Installation Failed: fatal: not in a git directory Error: Command failed with exit 128: git

0 comments97 views572 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

I ran into the following issues during this installation:

  1. Git submodules were not initialized or updated
  2. Incorrect ownership of the Homebrew core source code for the current user
  3. File conflicts prevented Homebrew from installing Node.js into /usr/local, and it listed some potentially conflicting files
  4. The directory /usr/local/share/doc/node was not writable

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:

The command output suggests that an error occurred while running brew install node. Specifically, it appears to have failed while installing the brotli dependency, with a Git-related message: fatal: not in a git directory.

This error may occur because Homebrew (the package manager) is trying to download the brotli source code from GitHub, but Git reports that the current directory is not in a Git repository and cannot proceed. This may be caused by Git submodules that have not been initialized or updated.

To resolve this, try running the following commands:

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

This enters the Homebrew core source directory and forces Git to initialize and update all submodules. Then run brew install node again, and Node.js should install successfully.

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

The command output shows that Git reported a "dubious ownership" error when running git submodule update --init --recursive. This error usually occurs because the Homebrew core source code has incorrect ownership for the current user.

To fix this, follow Git's suggestion and run:

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

This adds a "safe directory" exception in Git, allowing the current user to run Git operations in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core.

Then try running git submodule update --init --recursive again. All submodules should update successfully. Once that is done, run brew install node again, and Node.js should install successfully.

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

Based on the command-line output, brew install node successfully installed Node.js and its dependencies. However, after the final step, "Installing node", an error appeared:

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

This error is usually caused by file conflicts. In this case, Homebrew could not link Node.js into /usr/local and listed some potentially conflicting files.

To resolve this, try running the following command to overwrite all potentially conflicting files:

brew link --overwrite node

This forces Homebrew to overwrite any files that conflict with Node.js and link it into /usr/local. If needed, you can also use brew link --overwrite --dry-run node to see which files would be deleted. Once finished, run brew cleanup node again to clean up temporary files created during installation.

You can now run node -v to verify that Node.js was installed successfully.

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

Based on the command-line output, running brew link --overwrite node produced a new error: Homebrew could not link /usr/local/Cellar/node/19.9.0/share/doc/node/gdbinit because the directory /usr/local/share/doc/node is not writable.

This error is usually caused by the current user lacking write permissions for /usr/local. To resolve it, try the following:

  1. Run the Terminal application as an administrator. To do this, press Command + Space to open Spotlight, then type "Terminal" and press Enter. In the terminal window, enter the following command and press Enter:

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

    This changes the owner of /usr/local/share so you can write files and directories there.

  2. Run brew link --overwrite node again. Node.js should now install successfully. If you still encounter a similar error, try restarting your computer and then running brew link --overwrite node again.

Once finished, run node -v to verify that Node.js was installed successfully.

The Complete Process

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

Last updated 2024-01-14

Related posts

Comments 0