node.js NPM安装在安装express时出现错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17474687/
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-02 14:56:39  来源:igfitidea点击:

NPM install giving error installing express

node.jsubuntuexpressnpm

提问by Gaurav

When I give command npm install expressit throws following error. On ubuntu machine

当我发出命令时,npm install express它会引发以下错误。在 ubuntu 机器上

gaurav@gaurav-Mini-Monster:~/TestScripts$ sudo npm install -g express
npm ERR! error installing [email protected] Error: Unsupported
npm ERR! error installing [email protected]     at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing [email protected]     at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing [email protected]     at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing [email protected]     at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing [email protected]     at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:470:3)
npm ERR! error installing [email protected]     at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing [email protected]     at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing [email protected]     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing [email protected]     at Array.forEach (native)
npm ERR! error installing [email protected]     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back [email protected] Error: UNKNOWN, Unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: [email protected]
npm ERR! Required: {"node":">= 0.8.0"}
npm ERR! Actual:   {"npm":"1.0.106","node":"0.5.11-pre"}
npm ERR! 
npm ERR! System Linux 3.2.0-48-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /home/gaurav/TestScripts
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! code ENOTSUP
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/gaurav/TestScripts/npm-debug.log
npm not ok

I also tried

我也试过

sudo npm install express
npm install -g express
sudo npm install -g express

Nothing works.

什么都行不通。

回答by Thank you

Node is so easy to install manually. I like doing it this way too because it's really easy to switch versions.

手动安装 Node 非常容易。我也喜欢这样做,因为切换版本真的很容易。

This is also great because you don't need to add some external package repository to apt, and you don't have to wait for those repositories to update when node releases a new version. You can get updates as soon as they're released.

这也很棒,因为您不需要向 中添加一些外部包存储库apt,并且您不必在 node 发布新版本时等待这些存储库更新。您可以在发布后立即获取更新。

# make a `~/.nodes/ folder
mkdir -p ~/.nodes && cd ~/.nodes

# download the binaries from nodejs.org
# in this case, here's the linux version
curl -O http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-x64.tar.gz

# extract
tar -xzf node-v0.10.12-linux-x64.tar.gz

# rename folder to 0.10.12
mv node-v0.10.12-linux-x64 0.10.12

# create a `current` symlink
ln -s 0.10.12 current

# prepend ~/.nodes/bin to your path
# you'll want to save this in ~/.bashrc or ~/.zshrc or something
export PATH="~/.nodes/current/bin:$PATH"

# cleanup
rm ~/.nodes/node-v0.10.12-linux-x64.tar.gz


The best part about this is you can repeat the pattern for any other version of node, change the currentsymlink at any time to switch which version you're running, and you're good to go

最好的部分是您可以为任何其他版本的节点重复该模式,随时更改current符号链接以切换您正在运行的版本,您很高兴

% node --version
v0.10.12

% npm --version
1.2.32

# switch versions to (e.g.) 0.10.5
% cd ~/.nodes && rm current && ln -s 0.10.5 current

% node --version
v0.10.5

% npm --version
1.2.18


Additional pointers when writing executable scripts

编写可执行脚本时的附加指针

Make an executable file

制作可执行文件

% touch ~/somefile && chmod +x ~/someifle && nano ~/somefile

File contents

文件内容

#!/usr/bin/env node
console.log(process.version);

Run it

运行

% ./somefile
v0.10.12

回答by Peter Lyons

You are running a much-too-old version of nodeand npm. You have node v0.5 which is very out of date. Upgrade to node v0.10 and things will work.

您正在运行一个多太旧版本的nodenpm。您有非常过时的节点 v0.5。升级到节点 v0.10,一切都会好起来的。

Modern node.js versions for Ubuntu are available via this PPA from Chris Lea

可通过Chris Lea 的 PPA 获得适用于 Ubuntu 的现代 node.js 版本

To install:

安装:

sudo apt-get install python-software-properties
sudo add-apt-repository --yes ppa:chris-lea/node.js
sudo apt-get install nodejs

UPDATE

更新

It looks like your old version of node is installed at /usr/local/bin/node. The new version from the Chris Lea PPA will be at /usr/bin/node. So to verify all is well, do:

看起来您的旧版本节点安装在/usr/local/bin/node. Chris Lea PPA 的新版本将在/usr/bin/node. 因此,要验证一切正常,请执行以下操作:

/usr/bin/npm --version #Should be approx 1.2
/usr/bin/node --version #should be approx v0.10
/usr/bin/npm install -g express

You should uninstall the local node, or fix your PATH:

您应该卸载本地节点,或修复您的 PATH:

export PATH=/usr/bin:$PATH