问题描述
我使用的是苹果 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
但是,我查了一下,发现这两个文件确实存在。 有人能告诉我问题出在哪里吗?
这是我的 ~/.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/[email protected]/lib"
export CPPFLAGS="-I/Opt/homebrew/opt/[email protected]/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
解决方法
我遇到了类似的问题。我运行了 brew cleanup
来修复符号链接。
更详细的方法是:
brew doctor
brew cleanup
source ~/.zshrc
或一行:
brew doctor && brew cleanup && source ~/.zshrc
在此之后,您可以查看使用 source 后是否出现任何错误。
,根据https://github.com/Homebrew/homebrew-core/issues/45009
试试
sudo chown -R $(whoami):admin /usr/local/* \ && sudo chmod -R g+rwx /usr/local/*
然后
brew cleanup
没错,解决此问题的最简单方法是运行:brew cleanup
只是,如果您同时保留 arm 和 x86 版本,请不要忘记使用 x86 brew 版本运行此命令。
这是我的一个非常低级的错误,在我终于意识到我需要使用之前,我多次尝试使用默认的 brew 命令失败(我通过脚本安装它并且它已经链接到新的 arm 版本) x86 brew 执行 cleanup
命令。
@sinestandly 在其他方法失败后,上面的回答对我有用。我跑了 brew install zsh-completions
然后是 brew cleanup
。 cleanup
停止抛出错误,我不再收到错误消息 compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
。
谢谢@sinestandly!
,原来这些文件是另外两个不存在的文件的别名。
这是因为 M1 macbook 的 Homebrew 在 /opt/homebrew/
下,但 zsh 假设它仍然在 /usr/local
下。
因此,我删除了两个别名,并创建了指向文件实际位置的新别名:/opt/homebrew/completions/zsh/_brew
和/opt/homebrew/completions/zsh/_brew_cask
。
然后我使用了source ~/.zshrc
。没有错误信息。问题解决了!
我在卸载 brew 后遇到了这个问题。如果你做了同样的事情,只需将其删除:
rm -rf /usr/local/share/zsh/site-functions/_brew
,
int
修复它。
,我升级到 macOS Bigsur 后遇到了类似的问题。执行 brew update
我在更新 dot 文件时遇到了同样的问题。
在 M1 上,我从 Intel brew 到 Intel 和 ARM brew,然后再到 ARM 版本。我的问题是由两个符号链接引起的,它们指向不再存在的 Intel 版本,而不是 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
因此
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
我认为 _brew_cask 指向同一个 _brew 没问题,因为桶已经合并了。