AI Workshop: learn to build apps with AI →
npm: How to fix the "Missing write access" error when using npm

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


The first time you install a package globally with npm (npm install -g <package> on macOS or Linux), you may see an error like

Missing write access to /usr/local/lib/node_modules

npm error message

often followed by other errors or warnings.

This is a permission error: your user does not have write access to that directory. Fix it by changing ownership. Run:

sudo chown -R $USER /usr/local/lib/node_modules

What this does:

  • sudo runs the command as root (the system superuser), so the permission change can be applied. The system will prompt for your password.

  • chown changes the owner of a file or folder; -R applies the change recursively to all contents.

  • $USER is an environment variable set to your username.

  • The path is the directory from the error message.

After running this, you can run npm install -g <package> without permission errors.

Pay attention to the folder listed by the error message. If it’s different, update the chown command accordingly.

This tip applies to single user systems. On a multi-user system, you might want to create a dedicated directory for npm modules, see https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally.

Lessons in this unit:

0: Introduction
1: How to use or execute a package installed using npm
2: npm dependencies and devDependencies
3: ▶︎ How to fix the "Missing write access" error when using npm
4: npm can install packages in the parent folder
5: Install an older version of an npm package
6: Find the installed version of an npm package
7: How to test an npm package locally
8: npm global or local packages
9: What are peer dependencies in a Node module?
10: `npm run dev` is a long-running program
11: Semantic Versioning using npm
12: Uninstalling npm packages with `npm uninstall`
13: An introduction to the npm package manager
14: The npx Node Package Runner
15: The package.json guide
16: The package-lock.json file
17: What is pnpm?
18: Should you commit the node_modules folder to Git?
19: Update all the Node dependencies to their latest version
20: Where does npm install the packages?
21: Bumping Node.js dependencies
22: Run package.json scripts upon any file changes in a folder