2013-07-04 53 views
4

当我发出命令npm install express它引发以下错误。在Ubuntu机NPM安装给出错误安装快递

[email protected]:~/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 

我也试过

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

没有什么工作。

+0

什么是你的Ubuntu版本? – user568109

回答

16

节点是很容易的手动安装。我喜欢这样做,因为切换版本非常简单。

这也很棒,因为您不需要将一些外部软件包存储库添加到apt,并且在节点发布新版本时不必等待这些存储库进行更新。发布后您可以立即获得更新。

# 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 

这个最好的部分是可以重复的模式节点的任何其他版本,改变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 

其他指针制作一个可执行文件

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

文件内容

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

运行它

% ./somefile 
v0.10.12 
+0

谢谢@naomik。我用同样的方法来升级使用源代码的节点。问题解决了。学习到教训了 :) – Gaurav

10

您正在运行的版本太旧,nodenpm。你有节点v0.5,这是非常过时的。升级到节点v0.10,事情就会起作用。

现代的node.js版本的Ubuntu通过this PPA from Chris Lea

可用于安装:

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

UPDATE

它看起来像你的节点的旧版本安装在/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 

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

export PATH=/usr/bin:$PATH 
+3

我已正确识别您的问题。如果你不会付出比“不起作用”更多的努力来帮助我们,那么你就不值得我们的帮助。 –

+0

@PeterLyons起初你的评论似乎让我有点愤怒,但我已经更好地回答了问题和答案,而且你完全正确。 – gustavohenke

+0

sudo apt-get install python-software-properties - >这个命令很好用。 add-apt-respository命令也适用。但sudo apt-get install nodejs执行但仍然显示节点 - 版本v0.5.11-pre – Gaurav