我之前已经安装了 git,现在我想更新它,但是出现错误Error: git not installed
。该如何修复?
git --version
git version 2.21.0 (Apple Git-122)
type -a git
git is /usr/bin/git
which git
/usr/bin/git
brew upgrade git
Error: git not installed
brew uninstall git
Error: No such keg: /usr/local/Cellar/git
brew info git
git: stable 2.23.0 (bottled), HEAD
Distributed revision control system
https://git-scm.com
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb
==> Dependencies
Required: gettext ✘, pcre2 ✘
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 160,476 (30 days), 446,588 (90 days), 1,804,394 (365 days)
install_on_request: 149,046 (30 days), 415,976 (90 days), 1,656,545 (365 days)
build_error: 0 (30 days)
答案1
只需卸载并重新安装即可。
这种情况很少见,但有时在 Homebrew 中也会发生这种情况。我的做法是像这样卸载软件包:
brew remove --force --ignore-dependencies git
然后像这样重新安装:
brew install git
请记住,软件包安装的项目很容易移除和重新安装;所以在做任何其他事情之前,一定要依靠这个事实来解决问题。
如果仍然没有任何结果,我建议删除所有 Homebrew 包,然后使用以下命令重新安装它们:
brew remove --force --ignore-dependencies $(brew list);
或者用这种方法做类似的事情:
brew list -1 | xargs brew uninstall -f
然后只需按照通常的brew install
方式重新安装所需的东西即可。