How to Fix the 'zsh compinit: insecure directories' Error on macOS

Step-by-step guide to resolving the 'zsh compinit: insecure directories' error after installing Homebrew on macOS.

If you’ve recently installed the Homebrew package manager on macOS, you might encounter an error message in your Terminal similar to this:

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

This error can be frustrating, but don’t worry—this guide will walk you through the steps to resolve it. We’ll cover what causes the error and how to fix it quickly.

Understanding the Error

The error message relates to “insecure directories” and often appears when using the zsh shell after installing Homebrew.

Since macOS Catalina (version 10.15), zsh has been the default login shell. If you used earlier versions of macOS, you may not have seen this issue because bash was the default shell.

Identifying the Insecure Directories

To find out which directories are causing the problem, use the compaudit command:

$ compaudit
There are insecure directories:
/usr/local/share

In this example, /usr/local/share is flagged as insecure.

Resolving the Issue

To fix the zsh compinit: insecure directories error, follow these steps:

  1. Open Terminal.

  2. Run the following command:

compaudit | xargs chmod g-w

Here’s what this command does:

  • compaudit lists the insecure directories.
  • xargs passes each directory to chmod g-w.
  • chmod g-w removes group write permissions, making the directories secure.

After running this command, check again with compaudit:

$ compaudit
# No insecure directories (empty output)

You should no longer see the error.

Conclusion

Thanks for reading! I hope this guide helps you resolve the error on your macOS system.

See you next time!

References