35

所以我没有注意并运行了这个命令-

npm install npm install jasmine-node -g

这导致了这个 -

    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  npm@1.2.15 { [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

现在当我尝试跑步时

npm install jasmine-node -g

我明白了

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

这是怎么回事?

4

5 回答 5

115

当您运行 npm install -g somepackage 时,您可能会收到 EACCES 错误,要求您以 root/管理员身份再次运行该命令。这是权限问题。

容易修复,打开你的终端(应用程序>实用程序>终端)

sudo chown -R $USER /usr/local

** 我强烈建议你不要使用 sudo 进行包管理(sudo npm -g install something),因为以后可能会遇到一些问题**

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

** 更新 **

原因是这可能会导致许多其他应用程序出现权限问题,所以我建议不要这样做。

全局安装时更好的解决方案:

sudo chown -R `whoami` ~/.npm
于 2013-10-20T07:14:43.700 回答
30

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.

于 2013-03-26T09:19:07.037 回答
10

看看错误

Please try running this command again as root/Administrator.

你需要运行它sudo

$ sudo npm install jasmine-node -g
于 2013-03-26T09:07:29.493 回答
6

这对我有用(OSX)。我必须在我的用户目录中运行它。

cd ~

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

于 2014-06-06T19:16:39.293 回答
0

通过将我的包设置为使用单行“$HOME/.npmrc”文件在本地安装,我能够解决权限问题:

前缀=${HOME}/.npm_packages

于 2017-09-29T16:43:53.323 回答