Fixing npm permissions

https://docs.npmjs.com/getting-started/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 Responses so far.

  1. quest bars says:
    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. quest bars says:
    This is my first time pay a visit at here and i am really
    impressed to read all at one place.
  3. quest bars says:
    It’s very effortless to find out any topic on net as compared to books, as I found this
    article at this site.
  4. 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.
  5. 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.
  6. If you wish for to increase your experience simply keep visiting this web site and be updated with the most
    recent news posted here.
  7. It’s wonderful that you are getting ideas from
    this article as well as from our dialogue made at this place.
  8. This piece of writing will assist the internet users for
    setting up new weblog or even a blog from start to end.
  9. If some one desires expert view on the topic of blogging afterward i recommend him/her to go to
    see this webpage, Keep up the pleasant work.
  10. 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.
  11. I go to see everyday some websites and sites to read articles
    or reviews, but this blog presents quality based posts.
  12. Hi there friends, how is all, and what you desire to say concerning this post,
    in my view its truly awesome in support of me.
  13. 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.
  14. Ahaa, its fastidious conversation about this paragraph at this place
    at this web site, I have read all that, so at this time me also commenting
    at this place.
  15. great issues altogether, you just gained a new reader. What could you suggest about your post that you simply made a few days in the past? Any certain?

LEAVE A COMMENT