11

I get this error if I run

curl http://npmjs.org/install.sh | sh

even with sudo.

    cirk@cirk-Parallels-Virtual-Platform:~$ curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3902  100  3902    0     0   6138      0 --:--:-- --:--:-- --:--:-- 12546
fetching: http://registry.npmjs.org/npm/-/npm-1.0.18.tgz
0.4.9
1.0.18
Skipping 0.x cruft clean
! [ -d .git ] || git submodule update --init --recursive
node cli.js cache clean
node cli.js rm npm -g -f --loglevel error
node cli.js install -g -f
npm ERR! error installing npm@1.0.18 Error: EACCES, Permission denied '../lib/node_modules/npm/bin/npm.js'
npm ERR! Error: EACCES, Permission denied '../lib/node_modules/npm/bin/npm.js'
npm ERR! 
npm ERR! Please use 'sudo' or log in as root to run this command.
npm ERR! 
npm ERR!     sudo npm "install" "-g" "-f"
npm ERR! 
npm ERR! or set the 'unsafe-perm' config var to true.
npm ERR! 
npm ERR!     npm config set unsafe-perm true
npm ERR! 
npm ERR! System Linux 2.6.38-10-generic
npm ERR! command "node" "/tmp/npm.1568/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /tmp/npm.1568/package
npm ERR! node -v v0.4.9
npm ERR! npm -v 1.0.18
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /tmp/npm.1568/package/npm-debug.log
npm not ok
It worked

What should I do? I tried these with no success:

chown -R cirk /usr/lib/nodejs
// and also this
chown -R cirk /usr/lib/node_modules (node_modules is empty it tries to install NPM here or what)

actually it did something, as you can see it writes at the end It worked what is a big lie!

Kara
  • 6,115
  • 16
  • 50
  • 57
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
  • 1
    Been getting the same thing myself recently... – Paul Sonier Jul 19 '11 at 19:23
  • cool :) I´m getting tired here, I tried to fix it all the day, maybe some smart guys can help here :( – Adam Halasz Jul 19 '11 at 19:25
  • Did you try following the instructions in the error message (setting the unsafe-perm config var to true)? – Dan Grossman Jul 19 '11 at 19:26
  • @DanGrossman: you can't set the unsafe-perm config var to be true on NPM when you're trying to install NPM itself. I've tried. – Paul Sonier Jul 19 '11 at 19:28
  • @Dan Grossman no because npm is not installed, as I see `npm config set unsafe-perm true` method requires npm to be installed or I'm false? Exactly @Paul Sonier – Adam Halasz Jul 19 '11 at 19:29
  • 1
    Follow-up question: [Is it Safe to chown on /usr/lib?](http://unix.stackexchange.com/questions/16989/is-it-safe-to-chown-on-usr-lib/17007) Judging by this transcript, the installation script looks quite broken, both because it's apparently trying to write to `/usr/lib` (which is reserved for package managers, manual installations should go under `/usr/local`) and because it doesn't have proper error detection (the “It worked” bit). – Gilles 'SO- stop being evil' Jul 19 '11 at 20:56
  • 1
    It IS quite broken. The whole notion of running a shell script as root that you pull right off some site with curl is broken. – Keith Jul 20 '11 at 03:35
  • Voir aussi http://stackoverflow.com/a/27675564/1974961 – Hugolpz Dec 28 '14 at 12:27
  • Have you tried [these](https://gist.github.com/579814) methods? One of them should work (note; have not tried them all myself). – Paul Sonier Jul 19 '11 at 19:27
  • Just the first but did you made it? If yes which one helped you? I'm a bit afraid because I screwed up my Ubuntu twice today, and twice yesterday because of permissions :S – Adam Halasz Jul 19 '11 at 19:32
  • I haven't tried any of them yet; my system I'm installing node on has been having intermittent internet access. However, I can safely recommend using a VirtualBox setup for doing this type of install on; it removes the fear from the process. – Paul Sonier Jul 19 '11 at 19:36

2 Answers2

18

Why are you running that in /usr?

If you really need to, this page suggests you may run that as root, so that would be:

curl https://www.npmjs.com/install.sh | sudo sh

But you better make sure it won't break your system, before running that.

keparo
  • 33,450
  • 13
  • 60
  • 66
alex
  • 925
  • 1
  • 7
  • 9
  • maaan this worked, looool, ftw? I always put the sudo before the curl :)) I didń´t even noticed that sh is a command too, :D maan I´m very happy because I always had this issue when I installed NPM, and now I know why I failed. – Adam Halasz Jul 19 '11 at 20:42
  • @alex: the (recommended) default install of NPM puts stuff in /usr/lib. – Paul Sonier Jul 19 '11 at 21:10
  • I believe latest npm does not mind if you run as root => http://pastebin.com/BX9NVqF4 – Alfred Jul 19 '11 at 23:18
2

I screwed up the permissions on my npm installation, and had this error when reinstalling. I solved it in the crudest way: by liberally sudo rm -rfing any directory tree that gave me trouble, then recompiling node.js and reinstalling npm.

If all else fails, you could fall back to that.

Jeremy
  • 1
  • 85
  • 340
  • 366