NPM安装错误安装express。

时间:2022-01-20 19:46:48

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

当我命令npm安装时,它会抛出以下错误。在ubuntu的机器上

gaurav@gaurav-Mini-Monster:~/TestScripts$ sudo npm install -g express
npm ERR! error installing express@3.3.3 Error: Unsupported
npm ERR! error installing express@3.3.3     at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing express@3.3.3     at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing express@3.3.3     at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing express@3.3.3     at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing express@3.3.3     at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:470:3)
npm ERR! error installing express@3.3.3     at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing express@3.3.3     at Array.forEach (native)
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back express@3.3.3 Error: UNKNOWN, Unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect@2.8.3
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.

没有什么工作。

2 个解决方案

#1


16  

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添加一些外部包存储库,而且当节点发布新版本时,您不必等待这些存储库更新。你可以在他们发布的时候得到更新。

# 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 current symlink at any time to switch which version you're running, and you're good to go

最重要的是,您可以在任何其他版本的节点上重复这个模式,在任何时候更改当前的符号链接,以切换您正在运行的版本,并且您很好。

% 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

#2


10  

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

您正在运行一个非常旧版本的节点和npm。节点v0.5非常过时。升级到节点v0.10,事情就会成功。

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

现代的节点。Ubuntu的js版本是由Chris Lea提供的。

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:

您应该卸载本地节点,或者修复路径:

export PATH=/usr/bin:$PATH

#1


16  

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添加一些外部包存储库,而且当节点发布新版本时,您不必等待这些存储库更新。你可以在他们发布的时候得到更新。

# 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 current symlink at any time to switch which version you're running, and you're good to go

最重要的是,您可以在任何其他版本的节点上重复这个模式,在任何时候更改当前的符号链接,以切换您正在运行的版本,并且您很好。

% 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

#2


10  

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

您正在运行一个非常旧版本的节点和npm。节点v0.5非常过时。升级到节点v0.10,事情就会成功。

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

现代的节点。Ubuntu的js版本是由Chris Lea提供的。

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:

您应该卸载本地节点,或者修复路径:

export PATH=/usr/bin:$PATH