npm不会安装快递?

Dev*_*vin 46 node.js express

我目前有node.js版本0.8.8,并安装了npm 1.1.59.

每当我跑:

$ npm install -g express
Run Code Online (Sandbox Code Playgroud)

我得到了这个回报:

npm ERR! Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR!  { [Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/devinandrews/.npm/64a534c1-express.lock' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/devinandrews
npm ERR! node -v v0.8.8
npm ERR! npm -v 1.1.59
npm ERR! path /Users/devinandrews/.npm/64a534c1-express.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/devinandrews/npm-debug.log
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)

我现在正拉着我的头发试图解决这个问题.

更新:

我跑了

$ npm -g ls
Run Code Online (Sandbox Code Playgroud)

看看我在全球范围内安装了什么:

/usr/local/lib
??? express@3.0.0rc4
? ??? commander@0.6.1
? ??? connect@2.4.4
? ? ??? bytes@0.1.0
? ? ??? formidable@1.0.11
? ? ??? pause@0.0.1
? ? ??? qs@0.4.2
? ??? cookie@0.0.4
? ??? crc@0.2.0
? ??? debug@0.7.0
? ??? fresh@0.1.0
? ??? methods@0.0.1
? ??? mkdirp@0.3.3
? ??? range-parser@0.0.4
? ??? send@0.0.4
?   ??? mime@1.2.6
??? npm@1.1.59
  ??? abbrev@1.0.3
  ??? ansi@0.1.2
  ??? archy@0.0.2
  ??? block-stream@0.0.6
  ??? chownr@0.0.1
  ??? couch-login@0.1.10
  ??? fstream@0.1.18
  ??? fstream-npm@0.1.1
  ? ??? fstream-ignore@0.0.5
  ??? glob@3.1.12
  ??? graceful-fs@1.1.10
  ??? inherits@1.0.0
  ??? ini@1.0.4
  ??? init-package-json@0.0.5
  ? ??? promzard@0.2.0
  ??? lockfile@0.2.1
  ??? lru-cache@2.0.1
  ??? minimatch@0.2.6
  ??? mkdirp@0.3.4
  ??? node-gyp@0.6.7
  ??? nopt@2.0.0
  ??? npm-registry-client@0.2.6
  ??? npmconf@0.0.11
  ? ??? config-chain@1.1.1
  ?   ??? proto-list@1.2.2
  ??? npmlog@0.0.2
  ??? once@1.1.1
  ??? osenv@0.0.3
  ??? read@1.0.4
  ? ??? mute-stream@0.0.3
  ??? read-installed@0.0.2
  ??? read-package-json@0.1.4
  ??? request@2.9.203
  ??? retry@0.6.0
  ??? rimraf@2.0.2
  ??? semver@1.0.14
  ??? slide@1.1.3
  ??? tar@0.1.13
  ??? uid-number@0.0.3
  ??? which@1.0.5
Run Code Online (Sandbox Code Playgroud)

但如果我跑:

$ npm ls
Run Code Online (Sandbox Code Playgroud)

它返回空?

ty.*_*ty. 141

我有同样的问题,并npm cache clear没有解决它.导致此问题的原因是主.npm目录中的目录是使用root权限创建的.很可能你运行的第一个npm命令是sudo npm -g,现在你正在尝试npm install在本地目录中.

要解决:

  • sudo chown -R yourusername ~/.npm
  • 这可能没有必要,但我也必须这样做 rmdir ~/tmp

npm install 来自package.json应该在此之后工作.

  • @ConnorLeech没有,但总有一天你会想要没有sudo的`npm install`.我猜这个帖子的大部分流量都来自于此. (3认同)
  • 这不适合我.在home(`~`)目录中运行`ls -la`已经将我的Mac OS X用户名显示为我的`.npm`文件的所有者. (2认同)

sup*_*ova 6

运行npm cache clean 并尝试再次安装它


小智 6

我遇到了同样的问题,导致此问题的原因是您的主目录中的.npm目录是使用root权限创建的.

使用 :

$sudo npm install -g express
Run Code Online (Sandbox Code Playgroud)