zoukankan      html  css  js  c++  java
  • Ubuntu环境下使用npm安装node模块时报错的处理方法

    错误信息: 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了。

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

  • 相关阅读:
    HDU 4901 The Romantic Hero
    COGS8 备用交换机
    POJ 1466 Girls and Boys
    bzoj3442 学习小组
    bzoj2054 疯狂的馒头
    POJ2135 Farm Tour
    POJ 1149 PIGS
    Html5 Canvas学习之路(五)
    关于跨域简单总结
    vue-baidu-map 进入页面自动定位的解决方案!
  • 原文地址:https://www.cnblogs.com/starrytales/p/5642247.html
Copyright © 2011-2022 走看看