Fix: Missing write access to /usr/local/lib/node_modules while installing npm package globally into linux or mac

Shawon Saha - Oct 5 '23 - - Dev Community

One common issue that often crops up is the "Missing write access to /usr/local/lib/node_modules" error when trying to install npm packages globally. In this guide, we'll unravel this problem and provide you with a quick and effective solution. So, whether you're a seasoned Linux enthusiast or a newcomer, let's dive in and get your npm packages up and running without a hitch.

Solving the issue: Fixing the Permission Error

The root cause of this problem lies in a permission error that prevents you from writing to the specified folder. The solution? Let's grant ourselves the necessary permissions. Follow these steps:

  1. Open your terminal.
  2. Execute the following command:
sudo chown -R $USER /usr/local/lib/node_modules
Enter fullscreen mode Exit fullscreen mode

This command essentially changes the ownership of the /usr/local/lib/node_modules directory to your user account, granting you the required write access to successfully install npm packages globally.

If you still get error, try this:

sudo npm i -g <package name>
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player