You've successfully subscribed to StackInk
Great! Next, complete checkout for full access to StackInk
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Resolving EACCES Errors in NPM on MacOS

EACCES errors typically stem from insufficient permissions, often caused by attempting to install global packages. Here's what you need to do to fix it:

Step 1: Identify the problematic directory. Before diving into a solution, pinpoint the source of the problem. Run the following command in your terminal:


npm config get prefix

Take note of the directory that appears - the issue's root.

Step 2: Create a new directory for global packages. Instead of modifying permissions for the problematic directory, we'll create a new directory to store global packages. Execute the following command:


mkdir ~/.npm-global

This generates a new directory called "npm-global" within your home folder.

Step 3: Configure NPM to use the new directory. With our new directory in place, let's tell NPM to utilize it. Run this command:


npm config set prefix '~/.npm-global'

NPM now knows to reference the newly minted directory for global package installations.


Step 4: Update your system's PATH. For your system to find the installed packages, we must update the PATH. Open or create a file called ".bash_profile" (or ".zshrc" if using Zsh) in your home directory:


nano ~/.bash_profile

Add the following line to the file:


export PATH=~/.npm-global/bin:$PATH

Save the changes and exit the editor.

Step 5: Apply the changes to the current session. Lastly, we'll apply the changes to the active terminal session. Run the following command:


source ~/.bash_profile

Voilà! You have successfully reconfigured NPM to resolve EACCES errors on MacOS. Now, you can install global packages without worrying about those frustrating permission issues.