What is the difference between node vs nodejs command in terminal?

前端 未结 3 472
终归单人心
终归单人心 2020-12-09 14:52

I have untarred node.js from the tar file given on nodejs.org, but when i try executing my js program through node command nothing happens, but on the other hand nodejs comm

相关标签:
3条回答
  • 2020-12-09 15:25

    For sure available 'node' package is not related to nodejs.

    Just take a look at this node from here:

    https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

    There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

    So it seems like you may purge that radio program with

    dpkg --purge node
    

    And then install nodejs via one of common ways f.e. from precompiled deb packages available like this:

    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
    

    But nodejs updates faster than packages so after you will get any nodejs version available it's more efficient to use this module for managing nodejs versions - https://github.com/visionmedia/n

    At least after some tests this solution looks most suitable for me at mac os.

    0 讨论(0)
  • 2020-12-09 15:36

    This is highly dependent on many factors. Mainly, it depends on what node and nodejs in your shell actually are. You can check this using type node / type nodejs and/or which node / which nodejs (or perhaps whereis). This also depends on the OS and the shell.

    My guess is that which -a node will yield /usr/sbin/node which is not the nodejs executable and thus why it does not execute your node code. On my system, it is:

    /usr/bin/node -> /etc/alternatives/node -> /usr/bin/nodejs
    

    i.e. node is just a symbolic link to nodejs, which is the executable.

    You can also create this alias yourself so that it overrides whatever node is for you.

    0 讨论(0)
  • 2020-12-09 15:38

    Some of these answers were difficult to understand for me, so I'm going to write the answer that would've helped me.

    node is something like a radio telemetry solving program, they just happened to snag the name node first. nodejs is what you're after. So make sure you:

    apt-get install nodejs
    

    then, to fix the lame naming issue, create a symlink. A symbolic link between node and nodejs.

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

    The first part is the original file placement, and then where it should link to. You could also create an alias in your bash profile, which is also pretty easy.

    0 讨论(0)
提交回复
热议问题