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

15

214

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




Poolroom answered 16/1, 2021 at 7:11 Comment(2)
Do you (or the user you are running zsh under) have permission to read those files?Recoup
I think so, I used chmod 755 on these files.Poolroom
C
512

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

Cedrickceevah answered 27/1, 2021 at 17:33 Comment(3)
If you want to run a cleanup as a dry run, to see the intended effects first: brew cleanup -nMut
At the time of post i don't think brew cleanup workedSeparatrix
for me, the brew cleanup worked. You can read more about it here: github.com/ohmyzsh/ohmyzsh/issues/9602#issuecomment-768663375Nereid
S
65

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.

Separatrix answered 2/6, 2021 at 15:23 Comment(13)
missing an - for site-functions in the first lineIbex
Worked for me. (and yes - is missing)Akan
I fixed the typo, should be good to go. Thank you for the answer.Westerly
Thanks for correcting. Glad it’s helped some people. Yes some times on Mac a double hyphen gets turned into a double width hyphen I haven’t found out the cause yet probably a third-party tool . I will have a look this afternoon.Separatrix
Heck yeah, nice find! Fixed it for me on my M1.Schonthal
This worked for me. I still wonder why compinit would look for contents in /usr/local/share/. I checked echo $FPATH and there is /usr/local/share/zsh/site-functions after the ARM brew's /opt/homebrew/share/zsh-completions. I have no idea when and where was FPATH set to include the old paths.Dare
@Dare not sure. However, brew has had many releases since. These links were set by brews installation IIRC the issue was caused by moving from i386 to ARM64 architecture version of brew or trying to use both you can only have one set of symbolic links at a time. I think zsh sets some fpaths.Separatrix
Homebrew zsh is compiled using homebrew directories ( github.com/Homebrew/homebrew-core/blob/… ). You have directories for zsh completions and functions for the system, homebrew, zsh builtin, zsh third party (site-functions), user local under .zsh.Separatrix
Functions are also used with completions. I think they could probably use fpaths on their own these days? but perhaps the symbolic links are for backward compatibility.Separatrix
also brew cleanup didn’t solve the issue at the time of the postSeparatrix
This should be the accepted answer for M1. brew cleanup didn't work, at least for me.Loft
Fixed on M2, though _brew_cask isn't present on my machine, I see _brew_services - I symlinked both as indicated, and the error message is gone now.Ankara
bless you. this worked for me. M1.Kerr
R
48

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.

Rosenblum answered 17/4, 2021 at 7:37 Comment(0)
M
18

@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!

Meissner answered 31/7, 2021 at 18:3 Comment(2)
I was migrated from Intel to Apple Silicon (M1) and these solved the issue. Thanks! brew install zsh-completions brew cleanupArdeen
worked because zsh-completions actually recreates symbolic links for _brew which is the same given in my answer replacing missing or incorrect links. However, since _brew symbolic links have been removed from zsh-completions it just uses fpaths. It has also removed some other functionality because it was just duplicating what brew did. Just in case anyone found this not to work as expected.Separatrix
S
16

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
Squall answered 25/3, 2021 at 2:26 Comment(1)
I had a similar error not brew related but fix worked with sudo rm /usr/share/vendor-completions/_docker which was the line throwing errors. Basically a dead symlink pointer needing to be removed.Teide
A
12

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

Appel answered 18/2, 2021 at 16:39 Comment(2)
thanks. This worked for me. I was getting errors otherwise.Linalool
Not quite the same issue. You should be getting warnings from compinit regarding security permissions for this one. The above fixes this. However, should still work.Separatrix
P
8

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.

Patchwork answered 26/2, 2021 at 2:15 Comment(1)
if you're running both you should use the arch command to detect architecture then use if-else statements to load the paths, fpaths, symbolic links etc to match the version used and place all this into your .zshrc then either open your terminal for amd64 or use rosetta to load intel. You can actually duplicate your terminal app and have one set to each. just be wary of any background services.Separatrix
P
4

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!

Poolroom answered 17/1, 2021 at 3:28 Comment(6)
I guess you mean symlink, when you say 'aliases_? Files don't have aliases....Galvanize
Also, as it's been noted in https://mcmap.net/q/125693/-zsh-problem-compinit-503-no-such-file-or-directory-usr-local-share-zsh-site-functions-_brew, instead of removing the symlinks manually, it's more convenient/robust to run brew cleanup (which will remove any broken symlinks, including these ones). So I believe that should be the accepted answer.Lithia
I deleted the symlink _brew_cask, ran brew doctor and then brew cleanup. Nothing else worked for meRah
@Galvanize On Mac OS files have aliases. support.apple.com/guide/mac-help/…Emancipator
@RayBaxter: Interesting. What is the difference/advantage of a file alias over a symbolic link? For achieving this purpose, I would simply have created a symlink.Galvanize
@Galvanize I would have used a symlink as well. You can create an alias via the UI.Emancipator
R
4
brew install zsh-completions

Fixed it.

Reinertson answered 16/4, 2021 at 3:51 Comment(0)
U
4

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.

Uniformed answered 9/3, 2022 at 14:32 Comment(3)
Thank you! This works perfectly. One addition is that you need to add the eval that loads brew(eval "$(/opt/homebrew/bin/brew shellenv)") before the two lines listed in the answer.Willenewillet
Hi, somehow despite on a Apple Sillicon chips the brew --prefix still return me with /usr/local... is there a way to fix the problem?Anathema
This fixed my errors. Thanks! Now GIT autocomplete works!Bacardi
N
1

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

Nadene answered 17/5, 2021 at 3:48 Comment(1)
updating the brew solve my issueClair
B
1

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

Belligerency answered 9/9, 2022 at 0:45 Comment(0)
L
1

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

Leaving answered 1/9, 2023 at 20:24 Comment(0)
L
0

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

Running brew update && brew upgrade solved this.

Libation answered 31/3, 2022 at 10:28 Comment(0)
L
0

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.

Ladon answered 24/3 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.