zsh compinit: insecure directories error message on Mac, after installing Homebrew

随声附和 提交于 2021-01-27 04:42:18

问题


After installing Homebrew and Homebrew-Cask on my Mac (as administrator with user-id 'admin', running MacOS 10.12.6), I get the error message

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

every time I start zsh. Investing the issue with compaudit, I found mentioned several insecure directories, most related to Homebrew - for example /usr/local/share/zsh/site-functions. This directory and its entries have access rights 0755, which should be OK, but - for example - the entry

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

which is a symlink to a file in Homebrew which defines the completions for zsh, has the owner admin. My guess is that zsh wants to see the user root here.

If this were Linux, I would simply change the owner of these files to root, or rather, I would have made the whole installation as root in the first place. In MacOS 10.12 however, they even "administrators" are not allowed to take full control over the system and while I can login as administrator, I don't even know the password of root.

Is there a clever solution to this problem? Or, can we teach zsh compinit somehow to never ask this annoying question and either accept the insecure directories, or skip over them? Or would it be best to login as admin, and simply delete the offending symlinks from site-functions? I can live with a completion system, which does not know how to handle brew commands.


回答1:


I found, that the error message was generated by a call to compinit in my .zshrc, and that it can be turned off by passing the -i option, i.e.

 compinit -i

While this solves the problem, the argument brought by Ortomala Lokni that Homebrew should be installed using user privilege, is also worth considering - only that Homebrew does not allow me to do this; but this is a topic for a separate thread.




回答2:


You should not install Homebrew with sudo. According to the Homebrew FAQ:

Homebrew is designed to work without using sudo. You can decide to use it but we strongly recommend not to do so. If you have used sudo and run into a bug then this is likely to be the cause. Please don’t file a bug report unless you can reproduce it after reinstalling Homebrew from scratch without using sudo.

The solution is to reinstall Homebrew without sudo but the user need to be administrator of the computer as you can see in the install script:

elsif !`dsmemberutil checkmembership -U "#{ENV["USER"]}" -G admin`.include?("user is a member")
  abort "This script requires the user #{ENV["USER"]} to be an Administrator."


来源:https://stackoverflow.com/questions/55020408/zsh-compinit-insecure-directories-error-message-on-mac-after-installing-homebr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!