2

I have a nodejs package that requires a global install. This one fails in a way that leads me to believe there might be a configuration problem in the the Ubuntu package npm. This happens every-time I setup an Ubuntu 14.04 machine.

sudo apt-get install npm
npm install -g lineman

The npm -g command will throw some access error naming the local lib and bin directories. Unlike some global installs, it is not an option to cheat and run the second command under sudo. So, the only fix I have found that will work is something like this:

sudo chgrp -R $(whoami) /usr/local/bin /usr/local/lib
sudo chmod -R g+rwx /usr/local/bin /usr/local/lib

The fix is fine for me, I'm the only user. But is this really the best way to do it? I don't want to document my fix for anyone else that might use it in an environment where this will not work or cause trouble.

Also, should I file a bug report with someone who packages npm for Ubuntu?

jcalfee314
  • 4,642
  • 8
  • 43
  • 75
  • 1
    Its tricky but its definitely possible to install NPM packages without sudo on Ubuntu. You need to configure NPM to copy package files to a directory not owned by root. I use something like `/home//.npm` – Michael Coleman Feb 13 '15 at 00:47

2 Answers2

0

Instead of npm install -g lineman, you should run sudo npm install -g lineman. npm requires permission as well.

Also check this stackoverlfow link.

Community
  • 1
  • 1
  • 6
    Cracks me up how I get all day never use `sudo` with node or npm to prevent issue, but then everything online is recommending `sudo`. – Shane Jan 02 '16 at 05:49
  • 4
    try this if still wondering (after ~4 years): https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally – Jay Jodiwal May 22 '20 at 13:49
0

Using sudo is unsafe and completely is NOT recommended option to fix such error.

As Jay Jodiwal offered in the comment, the ONLY correct way to fix this error is using the official documentation on how to run npm without sudo.

https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

redCuckoo
  • 547
  • 6
  • 10