Rachel_Miller
Rachel_Miller

Reputation: 2343

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

I am using apple M1 MacBook pro.

When I installed oh my zsh. When I addedexport PATH="/opt/homebrew/bin:$PATH" to my ~/.zshrc file. This error was shown in my terminal:

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

However, I checked and found that these two files do exsist. Can someone tell me that the problem is?

This is my ~/.zshrc file:

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




Upvotes: 223

Views: 109465

Answers (16)

wonder
wonder

Reputation: 31

I had a similar problem. When I opened a term or VS Code term, it was displaying:

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

I fixed it by running:

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

After I created the symbolic links, that error disappeared.

It depends on where you installed oh my zsh. You can use brew --prefix to see. Usually it returns /opt/homebrew.

Upvotes: 0

FatherShawn
FatherShawn

Reputation: 213

The root of this problem is that the brew completions are not in $fpath. Verify that this is true for you:

echo $fpath

If you don't see /opt/homebrew/completions/zsh/ on an Apple Silicon Mac, then this is your root cause. Add this snippet to the top of your .zshrc

if type brew &>/dev/null; then
 fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
fi

See https://unix.stackexchange.com/questions/26555/fpath-in-zsh-functions-and-site-functions and https://formulae.brew.sh/formula/zsh-completions for sources I combined for this fix.

Upvotes: 0

AndrewC
AndrewC

Reputation: 830

I had the same this issue which I noticed when updating my dot files.

On the M1 I went from Intel brew to Intel and ARM brew then to just the ARM version. The problem for me was caused by two symbolic links pointing to the Intel version, which no longer existed, and not the ARM version.

I repaired it by changing the symbolic links to point to the right locations for the ARM version.

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

thus

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

I think _brew_cask pointing to the same _brew is okay since casks have been merged.

These folders are for shell completions. Just removing the links could result in breaking this functionality. What we have done here is manually repair them.

At the time brew cleanup didn’t resolve this particular issue. I believe some of the comments here where brew cleanup worked were because the issue was similar but didn’t have the same root cause.

Upvotes: 71

Joshua Varghese
Joshua Varghese

Reputation: 51

I was able to solve the issue by deleting the file that it was looking for. I just ran:

rm /usr/local/share/zsh/site-functions/_brew

I then confirmed that it worked by running source ~/zshrc

The reason was because the environment variable $fpath was looking in the directory /usr/local/share/zsh/site-functions/, and _brew was an empty link. Which is why I was getting the error:

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

Upvotes: 5

a13e
a13e

Reputation: 928

I had issue with /usr/local/share/zsh/site-functions/_mdatp and I deleted this link file and it worked perfectly

Upvotes: 1

Aleksei Trankov
Aleksei Trankov

Reputation: 31

Got the similar issue with another path, even doesn't mentioned in my .zshrc

Running brew update && brew upgrade solved this.

Upvotes: 0

lapponiandevil
lapponiandevil

Reputation: 433

All Homebrew completions were broken in my case, running on Apple Silicon. The move from /usr/local to /opt/homebrew in Homebrew 3.0.0 seems to be the issue.

I appended the new directory to FPATH in ~/.zshrc like so:

HOMEBREW_PREFIX=$(brew --prefix)
export FPATH="${HOMEBREW_PREFIX}/share/zsh/site-functions:${FPATH}"

If running Oh-My-Zsh, the lines need to go above the line that sources OMZ, since it does some completion magic of its own. Also remember to clean out your .zcomdump -files, which will be re-created.

Upvotes: 5

Andrew Kawel
Andrew Kawel

Reputation: 201

@sinestandly's answer above worked for me after the other methods failed. I ran brew install zsh-completions and then brew cleanup. The cleanup stopped throwing errors and I no longer get the error message compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask.

Thank you, @sinestandly!

Upvotes: 18

agent_daemon
agent_daemon

Reputation: 112

Got similar issue after I upgraded to macOS Bigsur. Got it fixed after doing brew update

Upvotes: 1

Philipos D.
Philipos D.

Reputation: 2310

An approach a little bit more detailed would be:

brew doctor
brew cleanup
source ~/.zshrc

Or one line:

brew doctor && brew cleanup && source ~/.zshrc

After this, you can see if you get any errors after using source.

Upvotes: 48

sinestandly
sinestandly

Reputation: 141

brew install zsh-completions

Fixed it.

Upvotes: 4

Micael Mota
Micael Mota

Reputation: 580

I got this issue after uninstalling brew. Just remove it if you've done the same:

rm -rf /usr/local/share/zsh/site-functions/_brew

Upvotes: 19

xsnaruto
xsnaruto

Reputation: 81

True, the easiest way to fix this problem is run: brew cleanup

Just, don't forget that run this command with the x86 brew version if u kept both of arm and x86 version.

This was a very low-level mistake of mine, I tried numerous times to fail with the default brew command (I installed it by the script and it already linked to the new arm version) before I finally realised I needed to use x86 brew to execute the cleanup command.

Upvotes: 8

Jerry
Jerry

Reputation: 367

According to https://github.com/Homebrew/homebrew-core/issues/45009

try

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

then

brew cleanup

Upvotes: 12

Monica Granbois
Monica Granbois

Reputation: 7212

I had a similar issue. I ran brew cleanup which fixed the symlinks.

Upvotes: 525

Rachel_Miller
Rachel_Miller

Reputation: 2343

Turns out these files are aliases of other two files that did not exist.

This is because the Homebrew of M1 macbook is under/opt/homebrew/ but the zsh assumed it is still under /usr/local.

So I deleted the two aliases and made new ones pointing to where the files actually are:/opt/homebrew/completions/zsh/_brewand/opt/homebrew/completions/zsh/_brew_cask.

Then I usedsource ~/.zshrc. No error messages. Problem solved!

Upvotes: 4

Related Questions