node: command not found

137,082

Solution 1

The node package is unrelated to NodeJS. See here for information about node Install node:

Amateur Packet Radio Node program (transitional package)


You should instead install the nodejs Install nodejs package.

sudo apt-get install nodejs

then use it with the nodejs command.

The reason node doesn't work is likely because of conflicts with the original node package linked above.


If you want npm Install npm, you'll have to install that as well.

sudo apt-get install npm

Solution 2

I agree, this is a bit of an issue but I don't know why it's happening.

The Fix

First things first, just create a symbolic link from called node pointing to the nodejs binary.

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

The Problem

Quite a few guides I found for installing Nodejs (here and here) all have similar code to test whether the installation happened correctly. So essentially create a simple server like so:

// hello_node.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

and then run it in nodejs with the following:

node hello_node.js

And then when I was trying to use npm to install something, it was failing and reporting the same node not found message.

Solution 3

Like @minerz029 already said there is a conflict with the node package. But if you still need the node command (because a script uses only nodefor example), the correct way is to install the nodejs-legacy package:

apt-get install nodejs-legacy

and not create a symlink on your own (especially not in /usr/bin/). This will provide a node command for nodejs.

Solution 4

Try this

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

sudo apt-get install -y nodejs

:)

Solution 5

may you need to install manually

sudo apt-get install npm
Share:
137,082

Related videos on Youtube

Matthieu Napoli
Author by

Matthieu Napoli

I am a software engineer passionate about code and human interactions around it. I like to work with great people, learn and get things done. You can read more about me on my blog or on my GitHub profile. Here are some projects I'm working on: bref.sh: deploy PHP on AWS Lambda to create serverless applications PHP-DI - Dependency injection library for PHP externals.io @matthieunapoli

Updated on September 18, 2022

Comments

  • Matthieu Napoli
    Matthieu Napoli almost 2 years

    I don't understand why the node command will not work, whereas nodejs works:

    $ node --version
    zsh: command not found: node
    $ nodejs --version
    v0.10.15
    

    I tried apt-get install nodejs, but the latest version is already installed.

    And furthermore:

    $ npm
    zsh: command not found: npm
    

    I thought npm was included in NodeJS > 0.10?

    • Matthieu Napoli
      Matthieu Napoli over 10 years
      @AhmedAl-battashi It doesn't help, I have already read it. NodeJS is installed, nodejs is in the PATH, but node and npm aren't available, I can't find them anywhere on my system.
    • yjwong
      yjwong over 10 years
      I'm not entirely sure, but I do recall that the reason why the node binary was renamed was because it conflicted with one of the packages called node (Amateur Packet Radio Node Program).
    • Braiam
      Braiam over 10 years
      Are you sure that you are looking for node and not nodejs? node is not what you think it is.
    • Matthieu Napoli
      Matthieu Napoli over 10 years
      @Braiam node is used in every tutorial I've seen
    • binki
      binki about 7 years
      It looks like the node package in Ubuntu will be renamed to ax25-node. So hopefully in the future Ubuntu will just install a binary named node when you install nodejs. @Braiam The de-facto standard shebang for node.js scripts is #!/usr/bin/env node, so Ubuntu sort of breaks standard node.js scripts because of its binary name conflict policy which was not respected by the node.js project.
  • Matthieu Napoli
    Matthieu Napoli over 10 years
    I read everywhere that I shouldn't install npm manually because it was included in > v0.10 :/ I'm a little lost
  • Matthieu Napoli
    Matthieu Napoli over 10 years
    I knew about the node package, however I don't see why a name package has any influence on the command line tool. For example, I don't install php, but php5-cli. But thanks for the answer, I was unsure if manually installing npm would be a problem, apparently it is not.
  • Simón
    Simón over 8 years
    Funny tip: there is a nodejs-legacy package that provides the symlink, purportedly for compatibility with "legacy code" that still relies on it.
  • grooveplex
    grooveplex about 8 years
    Installing the nodejs-legacy package lets you use either node or nodejs.
  • grooveplex
    grooveplex about 8 years
    @Simón I think it's a better solution than making a symbolic link.
  • Shawn Xie
    Shawn Xie about 8 years
    It works. I think this is better than @jlouzado's answer.
  • karel
    karel almost 7 years
    Why are you not installing the latest version?: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  • MUHASIN BABU
    MUHASIN BABU almost 7 years
    setup_6.x is stable
  • karel
    karel almost 7 years
    The LTS policy for Node.js version 8 is that it is pending LTS now, it starts being LTS in a few months in October, 2017, it starts maintenance period in April, 2019, and ends maintenance in December, 2019. For more information see the table in this answer: askubuntu.com/questions/626383/…
  • some bits flipped
    some bits flipped over 6 years
    unless you frequently "start from scratch" with your OS install .... MUCH better to let apt manage symlinks in bin. Thanks!
  • sudo
    sudo about 6 years
    So now I'm counting 3 packages I have to install if I'm doing basically anything with Node.js. I've been trying to install this one Node.js library for like an hour.
  • Vinayak
    Vinayak over 5 years
    I was unable to install asciicast2gif because during installation it runs node install.js and I get the error sh: 1: node: not found. This fixes it.