12.04中的grunt安装错误

12.04中的grunt安装错误

我尝试使用 npm 安装 grunt,但出现错误,而且没有提供太多详细信息。在此重现日志。

npm -v
1.1.4

sudo npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli

npm ERR! Error: failed to fetch from registry: grunt-cli
npm ERR!     at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR!     at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR!     at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR!     at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR!     at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
npm ERR!     at Request.emit (events.js:88:20)
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:412:12)
npm ERR!     at ClientRequest.g (events.js:156:14)
npm ERR!     at ClientRequest.emit (events.js:67:17)
npm ERR!     at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1256:7)
npm ERR! You may report this log at:
npm ERR!     <http://bugs.debian.org/npm>
npm ERR! or use
npm ERR!     reportbug --attach /home/raghav/npm-debug.log npm
npm ERR! 
npm ERR! System Linux 3.5.0-47-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /home/raghav
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: grunt-cli
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/raghav/npm-debug.log
npm not ok

尝试确认服务器是否可以正常访问,结果如下 -

ping registry.npmjs.org
PING a.sni.fastly.net (103.245.222.162) 56(84) bytes of data.
64 bytes from 103.245.222.162: icmp_req=1 ttl=50 time=243 ms

答案1

正如 @geon 指出的那样堆栈溢出

我使用 apt-get 安装 node。Npm 不包含在该软件包中,因此必须单独安装。我以为这样可行,但显然 Ubuntu 发行版中的 npm 版本已过时。

节点维基百科有这样的指令:

获取最新版本的 Node 或在旧版 Ubuntu 和其他基于 apt 的发行版上安装可能需要一些额外步骤。安装示例:

sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

此后,npm 已被包含在内并且运行完美。

相关内容