Software⏱️ 2 min read📅 2026-05-31

How to Fix: Permission denied when installing npm modules in OSX

Permission denied error when installing npm modules in OSX resolved through changing ownership and permissions.

Quick Answer: Change the ownership of the node_modules directory to your user account or run the command with elevated privileges.

The 'Permission denied' error when installing npm modules in OSX occurs due to a lack of write access to the system's root directory. This can be caused by various factors, including incorrect permissions or a missing `sudo` command.

💡 Why You Are Getting This Error

  • [Cause]

🔧 Proven Troubleshooting Steps

Method 1: Change Permissions

  1. Step 1: Open the Terminal and type `sudo chown -R $(whoami):staff /` to change the ownership of the user's home directory to your current username.

Method 2: Add sudo to Your Shell Profile

  1. Step 1: Open the Terminal and type `nano ~/.bash_profile` (or `~/.zshrc` if you're using zsh) to edit your shell profile.

Method 2: Add sudo to Your Shell Profile (continued)

  1. Step 2: Add the following line at the end of the file: `export PATH=$PATH:/usr/local/bin/sudo`

Method 2: Add sudo to Your Shell Profile (continued)

  1. Step 3: Save and close the file. Then, type `source ~/.bash_profile` (or `source ~/.zshrc`) to apply the changes.

✨ Wrapping Up

By following these methods, you should be able to resolve the 'Permission denied' error when installing npm modules in OSX.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions