zsh 问题:compinit:503:没有那个文件或目录:/usr/local/share/zsh/site-functions/_brew

Rac*_*ler 133 macos zsh apple-m1

我正在使用苹果 M1 MacBook pro。

当我安装 oh my zash 时。当我添加export PATH="/opt/homebrew/bin:$PATH"到我的 ~/.zshrc 文件时。此错误显示在我的终端中:

joe :: share/zsh/site-functions » source ~/.zshrc
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
Run Code Online (Sandbox Code Playgroud)

但是,我检查并发现这两个文件确实存在。有人能告诉我问题出在哪里吗?

这是我的 ~/.zshrc 文件:

Last login: Sat Jan 16 14:53:34 on console
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
[oh-my-zsh] Random theme 'jnrowe' loaded
? ~ ? cd ~
? ~ ? source .zshrc

compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
# export MANPATH="/usr/local/man:$MANPATH"
[oh-my-zsh] Random theme 'cypher' loaded
joe :: ~ » chmod 755 /usr/local/share/zsh
chmod 755 /usr/local/share/zsh/site-functions

joe :: ~ » sudo chmod 755 /usr/local/share/zsh
Password:
joe :: ~ » sudo chmod 755 /usr/local/share/zsh/site-functions
joe :: ~ » ls
#ZSH_DISABLE_COMPFIX=true

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

#Homebrew
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"
#Homebrew END

#Wget
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
#Wget END

 #Path to your oh-my-zsh installation.
export ZSH="/Users/caizhuoyue/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="random"

"~/.zshrc" 114L, 3999C




Run Code Online (Sandbox Code Playgroud)

Mon*_*ois 367

我有一个类似的问题。我跑了brew cleanup它修复了符号链接。

  • 如果您想以空运行方式运行清理,请首先查看预期效果:`brew cleanup -n` (7认同)

Phi*_* D. 22

一种更详细的方法是:

brew doctor
brew cleanup
source ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

或一行:

brew doctor && brew cleanup && source ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

在此之后,您可以查看使用 source 后是否出现任何错误。


小智 18

在其他方法失败后,@sinestandly 的上述答案对我有用。我跑brew install zsh-completions了然后brew cleanup。停止cleanup抛出错误,我不再收到错误消息compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask

谢谢你,@sinestandly!


小智 16

卸载brew后我遇到了这个问题。如果您也做了同样的事情,请将其删除:

rm -rf /usr/local/share/zsh/site-functions/_brew
Run Code Online (Sandbox Code Playgroud)


Jer*_*rry 8

根据https://github.com/Homebrew/homebrew-core/issues/45009

尝试

sudo chown -R $(whoami):admin /usr/local/* \ && sudo chmod -R g+rwx /usr/local/*

然后

brew cleanup


小智 7

没错,解决此问题的最简单方法是运行: brew cleanup

只是,如果您同时保留 arm 和 x86 版本,请不要忘记使用 x86 brew 版本运行此命令。

这是我的一个非常低级的错误,在我终于意识到我需要使用 x86 brew 之前,我多次尝试使用默认的 brew 命令失败(我通过脚本安装它并且它已经链接到新的 arm 版本)执行cleanup命令。


小智 7

我有同样的这个问题,我在更新我的点文件时注意到了这个问题。

在 M1 上,我从 Intel brew 到 Intel 和 ARM brew,然后再到 ARM 版本。对我来说,问题是由两个指向英特尔版本的符号链接引起的,英特尔版本不再存在,而不是 ARM 版本。

我通过更改符号链接以指向 ARM 版本的正确位置来修复它。

ln -fsv /opt/homebrew/completions/zsh/_brew /usr/local/share/zsh/site-functions/_brew

ln -fsv /opt/homebrew/completions/zsh/_brew /usr/local/share/zsh/site-functions/_brew_cask
Run Code Online (Sandbox Code Playgroud)

因此

lrwxr-xr-x    35 xxxx  2 Jun 16:02  _brew -> /opt/homebrew/completions/zsh/_brew
lrwxr-xr-x    35 xxxx  2 Jun 16:01  _brew_cask -> /opt/homebrew/completions/zsh/_brew
Run Code Online (Sandbox Code Playgroud)

我认为 _brew_cask 指向同一个 _brew 是可以的,因为桶已经合并了。

  • 已在 M2 上修复,尽管我的机器上不存在 _brew_cask,但我看到 _brew_services - 我按照指示对两者进行了符号链接,并且错误消息现在消失了。 (2认同)

Rac*_*ler 4

事实证明,这些文件是其他两个不存在的文件的别名。

这是因为 M1 macbook 的 Homebrew 是 under /opt/homebrew/,但 zsh 假设它仍然是 under /usr/local

因此,我删除了两个别名,并创建了指向文件实际位置的新别名:/opt/homebrew/completions/zsh/_brew/opt/homebrew/completions/zsh/_brew_cask

然后我用了source ~/.zshrc. 没有错误消息。问题解决了!

  • 另外,正如 /sf/answers/4614703971/ 中所述,运行 `brew cleanup` 会更方便/更强大(这将删除任何损坏的符号链接,包括这些符号链接),而不是手动删除符号链接)。所以我相信这应该是公认的答案。 (6认同)