无法创建符号链接share/git-core/contrib,/usr/local/share/git-core不可写。

13

我真的尝试了修复、卸载所有东西再重新安装等各种建议,但没有一个解决方案有效。我完全被卡住了,需要帮助找到解决方案!谢谢您提前的帮助,Christoph

MacBook-2:~ MyUserName$ brew install git
Warning: git-2.1.3 already installed, it's just not linked
MacBook-2:~ MyUserName$ brew destroy git
Error: Unknown command: destroy
MacBook-2:~ MyUserName$ brew uninstall git
Uninstalling /usr/local/Cellar/git/2.1.3...
MacBook-2:~ MyUserName$ brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-    2.1.3.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/git-2.1.3.yosemite.bottle.tar.gz
==> Pouring git-2.1.3.yosemite.bottle.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
 /usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
 /usr/local/share/git-core/contrib

Bash completion has been installed to:
 /usr/local/etc/bash_completion.d

zsh completion has been installed to:
 /usr/local/share/zsh/site-functions
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/git-core/contrib
 /usr/local/share/git-core is not writable.

You can try again using:
 brew link git
==> Summary
  /usr/local/Cellar/git/2.1.3: 1342 files, 32M
MacBook-2:~ MyUserName$ brew link git
Linking /usr/local/Cellar/git/2.1.3... 
Error: Could not symlink share/git-core/contrib
 /usr/local/share/git-core is not writable.
3个回答

29

这可能与权限相关的错误。

请尝试

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

或者,如果你只需要在 git-core 路径上这样做,

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

可能已经足够了。

然后运行

brew link git

再次。


@AWChristoph:这有帮助吗? - mattias
3
我认为你有点误解了我们使用chown -R的目的。每当你遇到一个新的“权限被拒绝”的消息时,这是因为当前运行brew命令的用户没有权限写入这些目录。因此,针对你发布的最新消息,你需要执行chown -R $(whoami) /usr/local/lib/perl5/。但是也许更容易的方法是直接执行sudo brew link git。不过,一般情况下不建议这样做。 - mattias
哦,在它前面加上 sudo。在所有需要更改当前用户不拥有的目录权限的情况下,您都需要使用 sudo。因此,sudo chown -R $(whoami) /usr/local/lib/perl5/ 应该可以解决您的问题。 - mattias
1
我正在运行ZSH,对我来说是这样的:sudo chown -R $(whoami) /usr/local/share/zsh/site-functions - originalhat
@DevinBrown:不如用sudo chown -R $(whoami) /usr/local/share/或者sudo chown -R $(whoami) /usr/local/share/git-core的方式?我会更新答案,以便适用于ZSH。 - mattias
显示剩余4条评论

13
也许您之前使用了sudo来安装某些应用程序,因此/usr/local/share//usr/local/lib目录的所有者变为root

执行:

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

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

然后运行:

brew link git

他告诉我:没有这样的桶:/usr/local/Cellar/git - mercury

0

更改权限之前,我会:

选项1:尝试卸载brew

1)保存您的brew软件包列表:

brew list > my_packages.txt

2) 然后卸载brew

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

3) 重新安装brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

4) 重新安装所有的软件包:

brew install $(< my_packages.txt )

选项2:

如果那个方法不起作用,请尝试运行:

brew doctor

使用以下代码检查是否可以修剪错误:

brew prune

参考资料


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接