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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more