Didn"t forge
2014-01-16 17:02
采纳率: 25%
浏览 345
已采纳

无法在 Ubuntu 中使用节点包管理器安装软件包

NodeJS interpreter name(node) on Ubuntu has been renamed to nodejs because of name conflict with another package. Here's what the readme.debian says:

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.

However, using nodejs mucks up installing packages using npm. Package installation fails with the following error:

sh: 1: node: not found
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

How do I make npm understand that nodejs is already installed on the system but the interpreter name is different?

转载于:https://stackoverflow.com/questions/21168141/cannot-install-packages-using-node-package-manager-in-ubuntu

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

16条回答 默认 最新

  • 胖鸭 2014-01-16 19:34
    已采纳

    TL;DR:

    sudo apt-get install nodejs-legacy
    

    First of all let me clarify the situation a bit. In summer 2012 Debian maintainers decided to rename Node.js executable to prevent some kind of namespace collision with another package. It was very hard decision for Debian Technical Committee, because it breaks backward compatibility.

    The following is a quote from Committee resolution draft, published in Debian mailing list:

    1. The nodejs package shall be changed to provide /usr/bin/nodejs, not /usr/bin/node. The package should declare a Breaks: relationship with any packages in Debian that reference /usr/bin/node.

    2. The nodejs source package shall also provide a nodejs-legacy binary package at Priority: extra that contains /usr/bin/node as a symlink to /usr/bin/nodejs. No package in the archive may depend on or recommend the nodejs-legacy package, which is provided solely for upstream
      compatibility. This package declares shall also declare a Conflicts: relationship with the node package.

    <...>

    Paragraph 2 is the actual solution for OP's issue. OP should try to install this package instead of doing symlink by hand. Here is a link to this package in Debian package index website.

    It can be installed using sudo apt-get install nodejs-legacy.

    I have not found any information about adopting the whole thing by NPM developers, but I think npm package will be fixed on some point and nodejs-legacy become really legacy.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • ℙℕℤℝ 2014-01-16 17:09

    Try linking node to nodejs. First find out where nodejs is

    whereis nodejs
    

    Then soft link node to nodejs

    ln -s [the path of nodejs] /usr/bin/node 
    

    I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.

    评论
    解决 无用
    打赏 举报
  • 妄徒之命 2015-08-09 14:01

    I fixed it unlinking /usr/sbin/node (which is linked to ax25-node package), then I have create a link to nodejs using this on command line

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

    Because package such as karma doesn't work with nodejs name, however changing the first line of karma script from node to nodejs, but I prefer resolve this issue once and for all

    评论
    解决 无用
    打赏 举报
  • 斗士狗 2015-08-14 11:34

    For me the fix was removing the node* packages and also the npm packages.

    Then a fresh install as:

    sudo apt-get install autoclean
    sudo apt-get install nodejs-legacy
    npm install
    
    评论
    解决 无用
    打赏 举报
  • 笑故挽风 2015-12-02 04:11

    Here's another approach I use since I like n for easy switching between node versions.

    On a new Ubuntu system, first install the 'system' node:

    curl -sL https://deb.nodesource.com/setup | sudo bash -
    

    Then install n module globally:

    npm install -g n
    

    Since the system node was installed first (above), the alternatives system can be used to cleanly point to the node provided by n. First make sure the alternatives system has nothing for node:

    update-alternatives --remove-all node
    

    Then add the node provided by n:

    update-alternatives --install /usr/bin/node node /usr/local/bin/node 1
    

    Next add node provided by the system (the one that was installed with curl):

    update-alternatives --install /usr/bin/node node /usr/bin/nodejs 2
    

    Now select the node provided by n using the interactive menu (select /usr/local/bin/node from the menu presented by the following command):

    update-alternatives --config node
    

    Finally, since /usr/local/bin usually has a higher precedence in PATH than /usr/bin, the following alias must be created (enter in your .bashrc or .zshrc) if the alternatives system node is to be effective; otherwise the node installed with n in /usr/local/bin takes always precedence:

    alias node='/usr/bin/node'
    

    Now you can easily switch between node versions with n <desired node version number>.

    评论
    解决 无用
    打赏 举报
  • python小菜 2016-01-07 17:54

    you can create a link ln -s nodejs node in /usr/bin hope this solves your problem.

    评论
    解决 无用
    打赏 举报
  • 零零乙 2016-02-10 00:52

    On Linux Mint 17, I tried both solutions (creating a symlink or using the nodejs-legacy package) without success.

    The only thing that finally worked for me was using the ppa from Chris Lea:

    sudo apt-get purge node-*
    sudo apt-get autoremove 
    sudo add-apt-repository ppa:chris-lea/node.js
    sudo apt-get update
    sudo apt-get install nodejs
    

    This installed node version 10.37 and npm 1.4.28. After that, I could install packages globally.

    评论
    解决 无用
    打赏 举报
  • from.. 2016-03-08 03:53
    sudo apt-get --purge remove node
    sudo apt-get --purge remove nodejs-legacy
    sudo apt-get --purge remove nodejs
    
    sudo apt-get install nodejs-legacy
    source ~/.profile
    

    Combined the accepted answer with source ~/.profile from the comment that has been folded and some clean up commands before. Most likely you will also need to sudo apt-get install npm after.

    评论
    解决 无用
    打赏 举报
  • ℙℕℤℝ 2016-03-21 14:09

    Uninstall whatever node version you have

    sudo apt-get --purge remove node
    sudo apt-get --purge remove nodejs-legacy
    sudo apt-get --purge remove nodejs
    

    install nvm (Node Version Manager) https://github.com/creationix/nvm

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
    

    Now you can install whatever version of node you want and switch between the versions.

    评论
    解决 无用
    打赏 举报
  • bug^君 2016-07-12 09:48
    1. Install nvm first using:

      curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
      
    2. Run command

      source ~/.profile
      
    3. Now run this and this will show will all installed or other versions of packages:

      nvm ls-remote
      
    4. Installed packages will be in green. Install whatever version you want:

      nvm install 6.0.0
      
    5. Check where is not installed:

      which node
      
    6. Check current version:

      node -v
      
      n=$(which node);
      n=${n%/bin/node}; 
      chmod -R 755 $n/bin/*; 
      sudo cp -r $n/{bin,lib,share} /usr/local
      
    评论
    解决 无用
    打赏 举报
  • MAO-EYE 2016-12-07 20:07

    Simple solution from here

    curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash --
    sudo apt-get install nodejs
    

    You can specify version by changing setup_x.x value, for example to setup_5.x

    评论
    解决 无用
    打赏 举报
  • ~Onlooker 2016-12-08 09:47

    As other folks already mention, I will suggest not to use "sudo apt-get" to install node or any development library. You can download required version from https://nodejs.org/dist/v6.9.2/ and setup you own environment.

    I will recommend tools like nvm and n, to manage you node version. It is very convenient to switch and work with these modules. https://github.com/creationix/nvm https://github.com/tj/n

    Or write basic bash to download zip/tar, extract move folder and create a soft link. Whenever you need to update, just point the old soft link to new downloaded version. Like I have created for my own, you can refer: https://github.com/deepakshrma/NodeJs-4.0-Reference-Guide/blob/master/nodejs-installer.sh

    #Go to home
    cd ~
    #run command
    #New Script
    wget https://raw.githubusercontent.com/deepakshrma/NodeJs-4.0-Reference-Guide/master/nodejs-installer.sh 
    bash nodejs-installer.sh -v lts
    #here -v or --version can be sepecific to 0.10.37 or it could be latest/lts 
    #Examples
    bash nodejs-installer.sh -v lts
    bash nodejs-installer.sh -v latest
    bash nodejs-installer.sh -v 4.4.2
    
    评论
    解决 无用
    打赏 举报
  • bug^君 2017-01-21 19:40

    Your System is not able to detect the path node js binary.

    1.which node

    2.Then soft link node to nodejs

    ln -s [the path of nodejs] /usr/bin/node 
    

    I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.

    评论
    解决 无用
    打赏 举报
  • 七度&光 2017-03-26 19:41

    Problem is not in installer
    replace nodejs with node or change the path from /usr/bin/nodejs to /usr/bin/node

    评论
    解决 无用
    打赏 举报
  • larry*wei 2017-08-02 15:55

    This is the your node is not properly install, first you need to uninstall the node then install again. To install the node this may help you http://array151.com/blog/nodejs-tutorial-and-set-up/

    after that you can install the packages easily. To install the packages this may help you

    http://array151.com/blog/npm-node-package-manager/

    评论
    解决 无用
    打赏 举报
  • 胖鸭 2017-08-03 11:07

    for me problem was solved by,

    sudo apt-get remove node
    sudo apt-get remove nodejs
    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    sudo apt-get install -y nodejs
    sudo ln -s /usr/bin/nodejs /usr/bin/node
    alias node=nodejs
    rm -r /usr/local/lib/python2.7/dist-packages/localstack/node_modules
    npm install -g npm@latest || sudo npm install -g npm@latest
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题