NPM no longer working

52,367

Solution 1

Tried it myself.

You will need to install npm again. If you use git, this is the easiest way:

git clone http://github.com/isaacs/npm.git
cd npm
sudo make install

Otherwise, there is an install script too:

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

(possibly you will need to use sudo sh instead of sh).

Then install your module again:

sudo npm install jasmine-node -g

EDIT 23/01/2014:

Now npm comes with NodeJs itself, so just reinstall NodeJs.

Solution 2

When you run npm install -g somepackage, you may get an EACCES error asking you to run the command again as root/Administrator. It's a permissions issue.

It's easy to fix, open your terminal (Applications > Utilities > Terminal)

sudo chown -R $USER /usr/local

** I strongly recommend you to not use the package management with sudo (sudo npm -g install something), because you can get some issues later **

Reference: http://foohack.com/2010/08/intro-to-npm/

** Update **

The reason is because this can cause permissions problems with lots of other apps, so I'd suggest not doing this.

A better solution when you are installing globally:

sudo chown -R `whoami` ~/.npm

Solution 3

Look at the error

Please try running this command again as root/Administrator.

You need to run this with sudo

$ sudo npm install jasmine-node -g

Solution 4

This worked for me (OSX). I had to run it in my user directory.

cd ~

curl -L http://npmjs.org/install.sh | sudo sh

Share:
52,367
praks5432
Author by

praks5432

Updated on September 30, 2020

Comments

  • praks5432
    praks5432 over 3 years

    so I wasn't paying attention and ran this command-

    npm install npm install jasmine-node -g
    

    which caused this -

        npm http GET https://registry.npmjs.org/install
    npm http GET https://registry.npmjs.org/jasmine-node
    npm http GET https://registry.npmjs.org/npm
    npm http 200 https://registry.npmjs.org/install
    npm http GET https://registry.npmjs.org/install/-/install-0.1.7.tgz
    npm http 200 https://registry.npmjs.org/install/-/install-0.1.7.tgz
    npm http 200 https://registry.npmjs.org/jasmine-node
    npm http GET https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz
    npm http 200 https://registry.npmjs.org/jasmine-node/-/jasmine-node-1.4.0.tgz
    npm http 200 https://registry.npmjs.org/npm
    npm http GET https://registry.npmjs.org/npm/-/npm-1.2.15.tgz
    npm http 200 https://registry.npmjs.org/npm/-/npm-1.2.15.tgz
    npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/install'
    npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/install']
    npm ERR!   errno: 3,
    npm ERR!   code: 'EACCES',
    npm ERR!   path: '/usr/local/lib/node_modules/install',
    npm ERR!   fstream_type: 'Directory',
    npm ERR!   fstream_path: '/usr/local/lib/node_modules/install',
    npm ERR!   fstream_class: 'DirWriter',
    npm ERR!   fstream_stack: 
    npm ERR!    [ 'DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
    npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
    npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    
    npm ERR! System Darwin 12.0.0
    npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
    npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
    npm ERR! node -v v0.8.17
    npm ERR! npm -v 1.2.0
    npm ERR! path /usr/local/lib/node_modules/install
    npm ERR! fstream_path /usr/local/lib/node_modules/install
    npm ERR! fstream_type Directory
    npm ERR! fstream_class DirWriter
    npm ERR! code EACCES
    npm ERR! errno 3
    npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/install'
    npm ERR! fstream_stack DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)
    npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
    npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
    npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node'
    npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node']
    npm ERR!   errno: 3,
    npm ERR!   code: 'EACCES',
    npm ERR!   path: '/usr/local/lib/node_modules/jasmine-node',
    npm ERR!   fstream_type: 'Directory',
    npm ERR!   fstream_path: '/usr/local/lib/node_modules/jasmine-node',
    npm ERR!   fstream_class: 'DirWriter',
    npm ERR!   fstream_stack: 
    npm ERR!    [ 'DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
    npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
    npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    
    npm ERR! System Darwin 12.0.0
    npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
    npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
    npm ERR! node -v v0.8.17
    npm ERR! npm -v 1.2.0
    npm ERR! path /usr/local/lib/node_modules/jasmine-node
    npm ERR! fstream_path /usr/local/lib/node_modules/jasmine-node
    npm ERR! fstream_type Directory
    npm ERR! fstream_class DirWriter
    npm ERR! code EACCES
    npm ERR! errno 3
    npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/jasmine-node'
    npm ERR! fstream_stack DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)
    npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
    npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
    npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
    npm ERR! error rolling back  [email protected] { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
    npm ERR! error rolling back   errno: 3,
    npm ERR! error rolling back   code: 'EACCES',
    npm ERR! error rolling back   path: '/usr/local/lib/node_modules/npm' }
    npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
    npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
    npm ERR!   errno: 3,
    npm ERR!   code: 'EACCES',
    npm ERR!   path: '/usr/local/lib/node_modules/npm' }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    
    npm ERR! System Darwin 12.0.0
    npm ERR! command "node" "/usr/local/bin/npm" "install" "npm" "install" "jasmine-node" "-g"
    npm ERR! cwd /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn
    npm ERR! node -v v0.8.17
    npm ERR! npm -v 1.2.0
    npm ERR! path /usr/local/lib/node_modules/npm
    npm ERR! code EACCES
    npm ERR! errno 3
    npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
    npm ERR! 
    npm ERR! Additional logging details can be found in:
    npm ERR!     /Users/psanker/Google Drive/Coding/Javascript/WhatsGoingOn/npm-debug.log
    npm ERR! not ok code 0
    

    Now when I try and run

    npm install jasmine-node -g
    

    I get

    -bash: /usr/local/bin/npm: No such file or directory
    

    What's going on?

  • romainberger
    romainberger over 11 years
    @praks5432 sudo not found? well, I'm sorry but that's all the help I can give you... I have no idea what to do in that case.
  • Gilney
    Gilney about 11 years
    This hint helped me in a Windows env install. The install was stuck in the second "GET" command, without any error message...
  • ThePrimeagen
    ThePrimeagen about 11 years
    Ahh yes, as my unixfoo is weak, i have been doing sudo curl://npmjs.org/install.sh | sh which has been erroring out. I did not realize that piping required another layer of sudo! Thanks
  • asgoth
    asgoth about 11 years
    @Michael Fell into that pitfall myself too ;)
  • Apurv Nerlekar
    Apurv Nerlekar over 10 years
    I understand the usage of separate user being beneficial against root access. Still i would not recommend doing "sudo chown -R $USER /usr/local". As here what you are trying to do is permitting everything in /usr/local to the $USER. I would not want that specific $USER to have all the permissions. The solution should just be finding the exact folder in /usr/local or whichever location and giving that only the right to be used by $USER. This too is drastically vulnerable to misuse. Another solution that i prefer is to "chmod" the exact package with SOME EXTRA permissions for separate users.
  • Jeff Ancel
    Jeff Ancel about 10 years
    I did this command, but qualifying it down to just the node_modules directory. /usr/local/lib/node_modules and it worked beautifully.
  • Juancarlos Rodríguez
    Juancarlos Rodríguez about 10 years
    @pruett you can install node using this gist
  • Juancarlos Rodríguez
    Juancarlos Rodríguez about 10 years
    @romainberger it's not a good idea to use npm as root, that will cause you problems later
  • Matt Fletcher
    Matt Fletcher almost 10 years
    The not found error is due to npm being available only to your user and not to root. Do what the highest rated answer says and just fix your permissions sudo chown -R $USER /usr/local - super simple.
  • vikingsteve
    vikingsteve over 8 years
    worked for me, as root: chown -R jenkins /opt/node and chgrp -R jenkins /opt/node
  • jason weng
    jason weng over 8 years