“Ubuntu 环境下npm使用时报错 node: not found 的处理方法”

来源:互联网 发布:js点击弹出对话框 编辑:程序博客网 时间:2024/06/02 04:47

错误信息: 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 0npm 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 insteaduse the "nodejs" command.

从上述文中中可以看出 在debian中 可执行文件node已经被修改成nodejs
因此npm执行的过程中找不到node可执行文件,故而出错。

执行命令

ll /usr/bin/node*

结果:

lrwxrwxrwx 1 root root      33 1022  2013 /usr/bin/node-gyp -> ../share/node-gyp/bin/node-gyp.js*-rwxr-xr-x 1 root root 1462424  327  2014 /usr/bin/nodejs*

从结果可知,可执行文件node意见改成了nodejs,这也是找不到 node 以及 npm install 安装一些模块时失败的原因
因此可执行文中开头的两种方法之一解决该问题

再次执行

ll /usr/bin/node*

结果:

lrwxrwxrwx 1 root root       6  327  2014 /usr/bin/node -> nodejs*lrwxrwxrwx 1 root root      33 1022  2013 /usr/bin/node-gyp -> ../share/node-gyp/bin/node-gyp.js*-rwxr-xr-x 1 root root 1462424  327  2014 /usr/bin/nodejs*

此时再次执行npm相关的指令就OK了。

说明:本人采用的是第一种方法。

0 0
原创粉丝点击