Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 870
Jacob Ford Avatar asked Oct 16 '19 18:10

Jacob Ford


2 Answers

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
like image 152
jasonleonhard Avatar answered Oct 24 '22 09:10

jasonleonhard


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)

like image 24
arekm Avatar answered Oct 24 '22 09:10

arekm