DEV Community

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

Posted on

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

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

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay