如何安全地解决 homebrew 和 zsh 对 /usr/local/share/zsh 所有权的冲突需求?
Posted
技术标签:
【中文标题】如何安全地解决 homebrew 和 zsh 对 /usr/local/share/zsh 所有权的冲突需求?【英文标题】:How can I safely resolve homebrew and zsh's conflicting needs for /usr/local/share/zsh ownership? 【发布时间】:2020-02-13 14:46:24 【问题描述】:在使用 macOS Catalina 更新将我的 shell 从 bash
切换到 zsh
之后,Homebrew 和 zsh 正在为他们需要如何拥有 /usr/local/share/zsh/site-functions
和 /usr/local/share/zsh
进行斗争。
zsh 更喜欢 /usr/local/share/zsh/**/*
归 root
所有,否则会引发烦人的错误
zsh compinit: insecure directories and files, run compaudit for list.
Ignore insecure directories and files and continue [y] or abort compinit [n]?
每次我以 root 身份登录时,例如通过sudo -s
。
我以 root 身份运行 compaudit
,然后运行 chown root
'd 和 chmod g-w
'd 它列出的所有目录。很满意zsh
,但现在homebrew
不开心了。
任何brew
install
或upgrade
都会失败
Error: The following directories are not writable by your user:
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/zsh /usr/local/share/zsh/site-functions
And make sure that your user has write permission.
chmod u+w /usr/local/share/zsh /usr/local/share/zsh/site-functions
brew doctor
给出与警告相同的消息。
两者之间有妥协吗?或者我可以安全地压制这些警告之一?如果有,怎么做?
【问题讨论】:
我为这个问题创建了一个discussion topic on the Homebrew Discourse。 【参考方案1】:我也遇到过类似情况,推荐如下:
brew update
brew upgrade
brew doctor
最后一个可能会确切地提到你需要做什么,在我的例子中这是一个简单的解决方案
brew cleanup
这删除了我之前显示的旧的冲突符号链接:
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
但是,如果您想在实际清理之前查看要清理的内容,您可以:
brew cleanup -n
brew cleanup --dry-run
【讨论】:
【参考方案2】:cd /usr/local/share/zsh/
下一个
chmod go-w site-functions
【讨论】:
但我需要它是可组写的:/【参考方案3】:我刚刚通过在我的 .zshrc
文件中添加以下行来使消息没有出现。
ZSH_DISABLE_COMPFIX="true"
如果不起作用,请尝试在.zshrc
文件的第一行添加该行。
【讨论】:
禁用COMPFIX
做了什么?我找不到文档。
Here 是COMPFIX
的源代码。它会标记不安全的目录。【参考方案4】:
在您的 .zshrc 中的某处有 compinit
调用。将其更改为compinit -u
,这将使警告静音。
/usr/share/zsh/5.7.1/functions/compinit 负责该警告(更改 5.7.1 以匹配您的 zsh 版本)
【讨论】:
确实在之后我以root身份登录。运行compinit
会触发错误,而compinit -u
会绕过它。但是,将 -u
标志添加到我的 compinit
调用中的 .zshrc
不起作用 - 我在运行 sudo -s
时仍然收到警告。
还有其他地方调用了compinit。例如,.zshrc 用于根或系统范围的配置。以上是关于如何安全地解决 homebrew 和 zsh 对 /usr/local/share/zsh 所有权的冲突需求?的主要内容,如果未能解决你的问题,请参考以下文章
設定MacOS 終端機環境 (Homebrew/zsh/oh-my-zsh/iTerm2)
解决zsh: command not found: gitk,将git路径/usr/bin/git修改为/usr/local/bin/git