npm install pm2 -g 报错 求指教
发布于 10 年前 作者 q1270989 33434 次浏览 最后一次编辑是 8 年前
OSError: [Errno 13] Permission denied
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 2.6.32-042stab083.2
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/pm2/node_modules/usage
gyp ERR! node -v v0.10.24
gyp ERR! node-gyp -v v0.12.1
gyp ERR! not ok 
npm http GET https://registry.npmjs.org/keypress
npm http 200 https://registry.npmjs.org/keypress
npm http GET https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz
npm http 200 https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz
npm ERR! usage[@0](/user/0).3.9 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the usage[@0](/user/0).3.9 install script.
npm ERR! This is most likely a problem with the usage package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls usage
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 2.6.32-042stab083.2
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "pm2" "-g"
npm ERR! cwd /usr/src/node-v0.10.24
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.21
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR! /usr/src/node-v0.10.24/npm-debug.log
npm ERR! not ok code 0

求教新弄了个VPS 结果安装 npm install pm2 -g

报错 请问咋回事?

补充一下 运行 npm install pm2 -g 会报错 运行 sudo npm install pm2 -g 提示 sudo:npm:找不到命令

系统是 centos6 64位

19 回复

which node 跑一下看下, 怀疑 Node 安装方式有问题, node 命令没出现在 $PATH 指定的路径里

which node 返回 /usr/local/bin/node 这样对么?

我是下的源码 然后直接 make install .

我现在node能跑,forever能跑,就是pm2安装不上 好郁闷.

@q1270989 不明白了… npm 命令也是这样的吗?

@jiyinyiyong 嗯 现在就是npm install pm2 -g 报错

我安装forever express jade socket.io 全部都没问题

好郁闷

-g 全局安装…你没权限啊…需要sudo啊…

@q1270989 … 难道真的因为 sudo, 前边几个命令怎么成功了

@jiyinyiyong 前面那几个不是全局安装…

@jiyinyiyong 但是我一用sudo npm 就是报错


= =!

@youxiachai forever 是全局的

用 sudo 提示 sudo:npm:找不到命令

@q1270989 多给些参数吧, 普通用户, root, 的 $PATH, 各种安装路径等等

@jiyinyiyong 私信你 VPS帐号

报错没贴全的样子, 一部分我附在后边了… 汗, 没能搞定… 大致了解到的东西,

  1. 楼主是用 root 在安装模块, 所以不用 sudo
  2. sudo env 的环境 $PATH 里没有 /usr/local/bin/, 所以找不到命令… 我不是很清楚 sudo 开的进程是怎么 copy 环境变量的, 反正比较奇怪. 我尝试创建一个有 sudo 权限的账户, 结果进入 sudo 模式 $PATH 还是缺的
  3. 照网上找的说法, npm 运行 node-gyp 时候开的子进程权限可能没有 root, 所以安装过程权限不足导致这个问题…
  4. 环境是 CentOS 6.0 , Node 和 npm 都在 /usr/local/bin/
[root@www ~]# npm install -g pm2
npm http GET https://registry.npmjs.org/pm2
npm http 304 https://registry.npmjs.org/pm2
npm http GET https://registry.npmjs.org/cli-table/0.2.0

....

npm http 304 https://registry.npmjs.org/configurable/0.0.1
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/colors/0.3.0
npm http 304 https://registry.npmjs.org/escape-regexp/0.0.1

> usage@0.3.9 install /usr/local/lib/node_modules/pm2/node_modules/usage
> node-gyp rebuild

Traceback (most recent call last):
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 534, in script_main
    return main(sys.argv[1:])
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 527, in main
    return gyp_main(args)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 503, in gyp_main
    options.circular_check)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 129, in Load
    params['parallel'], params['root_targets'])
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2687, in Load
    generator_input_info)
  File "/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 594, in LoadTargetBuildFilesParallel
    parallel_state.pool = multiprocessing.Pool(8)
  File "/usr/lib64/python2.6/multiprocessing/__init__.py", line 227, in Pool
    return Pool(processes, initializer, initargs)
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 84, in __init__
    self._setup_queues()
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 131, in _setup_queues
    self._inqueue = SimpleQueue()
  File "/usr/lib64/python2.6/multiprocessing/queues.py", line 328, in __init__
    self._rlock = Lock()
  File "/usr/lib64/python2.6/multiprocessing/synchronize.py", line 117, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1)
  File "/usr/lib64/python2.6/multiprocessing/synchronize.py", line 49, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 13] Permission denied
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16)

https://github.com/Unitech/pm2/issues/232#issuecomment-31238551

看到一个貌似跟我错误一样的 不知道pm2的人能解答不

其实我没sudo,好像也全局安装了

前面能成功是因为 npm install 的默认路径是 ~/.npm 一般都有权限…

sudo 不成功要么是脚本没有可执行权限,或者 sudo 的 PATH 跟当前帐号不一样。

http://stackoverflow.com/questions/12996397/command-not-found-when-using-sudo

跟你贴的这个issue 应该关系不大…

汗,今天遇到和你一样的事情,结果是因为root 默认环境变量里面没有/usr/local/bin,所以root找不到node和npm,sudo npm就报错了,在/etc/sudoers里面加上这个路径久可以了

怎么解决的?

回到顶部