bash npm 安装失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13964173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:03:23  来源:igfitidea点击:

npm install failing

linuxbashnode.jsshellnpm

提问by Danny

I'll start off by saying that I have next to no experience working in terminal or with node.js.

我首先要说我几乎没有在终端或 node.js 中工作的经验。

Coworker left for vacation and I'm trying to follow instructions he left for setting up his app on our demo server. I can get everything running locally, but am running into issues on the server installing socket.io module.

同事去度假了,我正在尝试按照他留下的说明在我们的演示服务器上设置他的应用程序。我可以让一切都在本地运行,但是在安装 socket.io 模块的服务器上遇到了问题。

Installed python, installed nodejs, both successful. But then I issue the command:

安装python,安装nodejs,都成功了。但后来我发出命令:

npm install -g socket.io

And the output I get is:

我得到的输出是:

npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/socket.io'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/socket.io']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/socket.io',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/socket.io',
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 Linux 2.6.32-279.el6.x86_64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "socket.io"
npm ERR! cwd /home/qa
npm ERR! node -v v0.8.16
npm ERR! npm -v 1.1.69
npm ERR! path /usr/local/lib/node_modules/socket.io
npm ERR! fstream_path /usr/local/lib/node_modules/socket.io
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/socket.io'
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!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/qa/npm-debug.log
npm ERR! not ok code 0

The account I'm on should have admin privileges. Googling around I found some suggestions but none seemed to work for me. Tried prepending command with sudo but get:

我所在的帐户应该具有管理员权限。谷歌搜索我发现了一些建议,但似乎没有一个对我有用。尝试使用 sudo 预置命令,但得到:

[qa@umr-demo ~]sudo npm install -g socket.io
[sudo] password for qa:
sudo: npm: command not found

回答by Pau Fracés

I have the same error if not privileged, so I must use sudo when using the -gflag

如果没有特权,我也有同样的错误,所以在使用-g标志时我必须使用 sudo

If sudo don't recongize npm you can try:

如果 sudo 不认识 npm,您可以尝试:

  • passing the complete route of npm

    $ sudo $(which npm) install -g socket.io
    
  • preserving the environment with -E flag

    $ sudo -E npm install -g socket.io
    
  • 通过npm的完整路线

    $ sudo $(which npm) install -g socket.io
    
  • 使用 -E 标志保护环境

    $ sudo -E npm install -g socket.io
    

Upd:

更新:

Note that is recommended to use the -gflag only for executablesand install locally (without the flag) the libraries that are required in your code. Privileges are required for copying the executables to /usr/binor, in your case /usr/local/bin

请注意,建议-g标志用于可执行文件,并在本地(不带标志)安装require代码中的库。将可执行文件复制到/usr/bin或在您的情况下需要特权/usr/local/bin

Note too that in the socket.io site, the -gflag is not included for the installation command ;)

还要注意,在 socket.io 站点中,-g安装命令不包含该标志;)

Read more: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/

阅读更多:http: //blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/

回答by bobbaluba

If you are on Arch Linux, check out the npm2archpackage in the AUR. It will let you install npm packages using pacman.

如果您使用的是 Arch Linux,请查看npm2archAUR 中的软件包。它将让您使用 pacman 安装 npm 包。

Example:

例子:

npm2archinstall socket.io