Fixing npm permissions


You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.

You can fix this problem using one of two options:

  1. Change the permission to npm’s default directory.
  2. Change npm’s default directory to another directory.

You should back-up your computer before moving forward.

  1. Find the path to npm’s directory:
     npm config get prefix

For many systems, this will be /usr/local.

WARNING: If your path is /usr, switch to option 2.

  1. Change the owner of npm’s directory’s to the effective name of the current user (your username!):
     sudo chown -R `whoami` <directory>

If you don’t want to change the permissions on the entire directory, you can change permissions on the subfolders lib/node_modules, bin, and share.

There are times when you do not want to change ownership of the default directory that npm uses; for example, if you are sharing a machine with other users.

In this case, you can configure npm to use a different directory.

  1. Make a directory for global installations:
     mkdir ~/npm-global
  2. Configure npm to use the new directory path:
     npm config set prefix '~/npm-global'
  3. Open or create a ~/.profile file and add this line:
     export PATH=~/npm-global/bin:$PATH
  4. Back on the command line, update your system variables:
     source ~/.profile

Test: Download a package globally without using sudo.

    npm install -g jshint

15 thoughts on “Fixing npm permissions

  1. Hi! I know this is kind of off topic but I was
    wondering which blog platform are you using for this website?
    I’m getting fed up of WordPress because I’ve had issues with hackers and I’m looking at alternatives for another platform.
    I would be awesome if you could point me in the direction of a good platform.

  2. I have been exploring for a little for any high quality articles or blog posts on this kind
    of space . Exploring in Yahoo I at last stumbled upon this
    web site. Studying this information So i’m glad to exhibit that
    I’ve a very just right uncanny feeling I discovered just what
    I needed. I such a lot certainly will make certain to don?t
    forget this site and give it a look on a relentless basis.

  3. What’s Happening i am new to this, I stumbled upon this I have discovered It absolutely helpful
    and it has aided me out loads. I am hoping to contribute & aid
    different customers like its helped me. Great job.

  4. We’re a group of volunteers and opening a new scheme in our community.
    Your website offered us with useful information to work
    on. You’ve performed an impressive job and our entire community
    will probably be thankful to you.

  5. Just desire to say your article is as astounding. The clarity in your post is simply nice and i
    could assume you’re an expert on this subject. Fine with your permission let me
    to grab your feed to keep updated with forthcoming post.
    Thanks a million and please keep up the gratifying work.

Leave a Reply

Your email address will not be published. Required fields are marked *