Fixing npm permissions

Nikhil M

1 min read

From the archive: this article was published in February 2017 and is kept for reference. Tools, versions and figures may have changed since.

This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.

How bad is it?

npm ERR! Linux 3.19.0-49-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "hapi"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/light/npm-debug.log

Read official documentation

You can fix this problem using one of three options:

  • Change the permission to npm’s default directory.
  • Change npm’s default directory to another directory.
  • Install node with a package manager that takes care of this for you.

How to Fix?

Please check this gist

  • Run cd ~
  • Run wget http://pastebin.com/raw/1ccE6EgF -O fix_npm.sh
  • Run chmod +x fix_npm.sh
  • Run ./fix_npm.sh

This article originally appeared on lightrains.com

Leave a comment

To make a comment, please send an e-mail using the button below. Your e-mail address won't be shared and will be deleted from our records after the comment is published. If you don't want your real name to be credited alongside your comment, please specify the name you would like to use. If you would like your name to link to a specific URL, please share that as well. Thank you.

Comment via email

Share this article

Topic

More on Engineering Insights

Tools, languages and practices from the Lightrains team, and how offshore engineering teams work.

Written by

Nikhil M

Managing Director

Entrepreneur / Privacy Freak / Humanist / Blockchain / AI / Digital Security / Online Privacy

Keep reading

Ready to build your next AI product?

Get a free consultation and project quote for AI, software or product development, tailored to your goals.

  • No-obligation consultation
  • Clear scope and timeline
  • Transparent pricing
Get your free project quote