Jacob Ford
Jacob Ford

Reputation: 5193

How can I safely resolve homebrew and zsh's conflicting needs for /usr/local/share/zsh ownership?

After switching my shell from bash to zsh with the macOS Catalina update, Homebrew and zsh are fighting over how they need /usr/local/share/zsh/site-functions and /usr/local/share/zsh to be owned.

zsh prefers that /usr/local/share/zsh/**/* be owned by root, and otherwise raises the annoying error

zsh compinit: insecure directories and files, run compaudit for list.
Ignore insecure directories and files and continue [y] or abort compinit [n]?

every time I log in as root, for example via sudo -s.

I ran compaudit as root then chown root'd and chmod g-w'd all the directories that it listed. That satisfied zsh but now homebrew isn't happy.

Any brew install or upgrade fails with

Error: The following directories are not writable by your user:
/usr/local/share/zsh
/usr/local/share/zsh/site-functions

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/zsh /usr/local/share/zsh/site-functions

And make sure that your user has write permission.
  chmod u+w /usr/local/share/zsh /usr/local/share/zsh/site-functions

brew doctor gives the same message as a warning.

Is there a compromise between the two? Or one of these warnings I can safely suppress? If so, how?

Upvotes: 16

Views: 15103

Answers (4)

jasonleonhard
jasonleonhard

Reputation: 13907

I had a similar situation, I recommend the following:

brew update 
brew upgrade 
brew doctor 

The last one might mention exactly what you need to do, in my case it was a simple solution

brew cleanup 

This removed the old conflicting symlink I was showing prior:

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

However if you want to see what would be cleaned up prior to actually cleaning up you can:

brew cleanup -n
brew cleanup --dry-run

Upvotes: 3

Alfredo Mtz G
Alfredo Mtz G

Reputation: 31

cd /usr/local/share/zsh/

next

chmod go-w site-functions

Upvotes: 3

boo
boo

Reputation: 179

I just made the message does not come up by adding the following line in my .zshrc file.

ZSH_DISABLE_COMPFIX="true"

If it does not work, try to add the line on the first line of the .zshrc file.

Upvotes: 5

arekm
arekm

Reputation: 56

There is compinit call somewhere like in your .zshrc. Change it to compinit -u which will silence the warning.

/usr/share/zsh/5.7.1/functions/compinit is responsible for that warning (change 5.7.1 to match your zsh version)

Upvotes: 1

Related Questions