歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Ubuntu環境下使用npm時報錯的處理方法

Ubuntu環境下使用npm時報錯的處理方法

日期:2017/3/1 11:44:36   编辑:關於Linux

錯誤信息: npm ERR ; node: not found ; npm ERR! not ok code 0

解決方案:

sudo apt-get install nodejs-legacy

也可以嘗試

ln -s /usr/bin/nodejs  /usr/bin/node

問題解決思路:

本人是在安裝hexo時出現的錯誤,即下列操作

npm install hexo-cli -g

錯誤信息中有如下信息

npm ERR! not ok code 0
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

根據提示信息打開文件

vim /usr/share/doc/nodejs/README.Debian

文件中7-8行文字:

The global search path for modules is /usr/lib/nodejs

32-40行文字:

The upstream name for the Node.js interpreter command is "node".
In Debian the interpreter command has been changed to "nodejs".

This was done to prevent a namespace collision: other commands use 
the same name in their upstreams, such as ax25-node from the "node"
package.

Scripts calling Node.js as a shell command must be changed to instead
use the "nodejs" command.

從上述文中中可以看出 在debian中 可執行文件node已經被修改成nodejs
因此npm執行的過程中找不到node可執行文件,故而出錯。

執行命令

ll /usr/bin/node*

結果:

lrwxrwxrwx 1 root root      33 10月 22  2013 /usr/bin/node-gyp -> ../share/node-gyp/bin/node-gyp.js*
-rwxr-xr-x 1 root root 1462424  3月 27  2014 /usr/bin/nodejs*

從結果可知,可執行文件node意見改成了nodejs,這也是找不到 node 以及 npm install 安裝一些模塊時失敗的原因
因此可執行文中開頭的兩種方法之一解決該問題

再次執行

ll /usr/bin/node*

結果:

lrwxrwxrwx 1 root root       6  3月 27  2014 /usr/bin/node -> nodejs*
lrwxrwxrwx 1 root root      33 10月 22  2013 /usr/bin/node-gyp -> ../share/node-gyp/bin/node-gyp.js*
-rwxr-xr-x 1 root root 1462424  3月 27  2014 /usr/bin/nodejs*

此時再次執行npm相關的指令就OK了。

說明:本人采用的是第一種方法。

Copyright © Linux教程網 All Rights Reserved