ohmyzsh: compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew

I am using Apple M1.

When I added this line: export PATH="/opt/homebrew/bin:$PATH" to ~/.zshrc file. These error messages came up: 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

I dont know that’s the problem and how to fix this.

I went to the directory /usr/local/share/zsh/site-functions and these two files do exist. Also, I used chmod 755 /usr/local/share/zsh/site-functions/_brew and chmod 755 /usr/local/share/zsh/site-functions/_brew_chask

My ~/.zshrc file:

#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

Problem solved.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Per https://github.com/ohmyzsh/ohmyzsh/issues/9602#issuecomment-768532307, brew cleanup fixed it for me.

(And you can do a “dry run” with brew cleanup -n to see what would happen during the cleanup without actually executing it.)

I had to run brew install brew-cask-completion, which solved the issue.

This is not specific to M1 chip. But brew cleanup seems to have fixed the issue

This is a Homebrew problem. See here and the fix

Try rm ~/.zcompdump* and then exec zsh.

I went to the directory /usr/local/share/zsh/site-functions and these two files do exist. Also, I used chmod 755 /usr/local/share/zsh/site-functions/_brew and chmod 755 /usr/local/share/zsh/site-functions/_brew_chask

These are probably symlinks to other files that do not exist. Use ls -l /usr/local/share/zsh/site-functions/_brew* to see where they point.

Thanks again for your promp reply! This is what I got from using ls -l /usr/local/share/zsh/site-functions/_brew* :

lrwxr-xr-x  1 caizhuoyue  admin  39  1 16 09:17 /usr/local/share/zsh/site-functions/_brew -> ../../../Homebrew/completions/zsh/_brew
lrwxr-xr-x  1 caizhuoyue  admin  44  1 16 09:17 /usr/local/share/zsh/site-functions/_brew_cask -> ../../../Homebrew/completions/zsh/_brew_cask

So,these are symlinks. And they point to usr/local/Homebrew/completions/zsh/_brew_cask. However, for M1 homebrew is under /opt/homebrew. I guess that’s the problem.

Any idea how to fix it? Make the symlinks point to the files under /opt/homebrew? Would that work?

Oh, actually, it’s two aliases. I made new ones pointing to /opt/homebrew/completions/zsh/_brew and /opt/homebrew/completions/zsh/_brew_cask . Then I deleted the old aliases.

When I used source ~/.zshrc, no more error messages!

Problem solved! Thank you so much 😃

I had this issue too. Tried running brew cleanup and brew cleanup -n as recommended by @jsejcksn but still had the same issue.

Ended up just deleting the broken alias (rm /usr/local/share/zsh/site-functions/_brew_cask) and running brew doctor / brew cleanup again and it seemed to fix it after a quick reload.

brew doctor brew cleanup source .zshrc

Great! You might want to make an issue on the Homebrew project or post a new discussion in https://github.com/Homebrew/discussions to get more specific support as to why this is like this. It might be a bug or something.

PS. Also it’s better to use exec zsh to reload the zsh session, source ~/.zshrc could have side effects.

The PATH directory should use forward slashes: export PATH="/opt/homebrew/bin:$PATH". If that doesn’t solve it, which it probably won’t, try rm $ZSH_COMPDUMP and restart zsh with exec zsh.