51

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?

6
  • may this post solve your problem [Stackoverflow][1] [1]: stackoverflow.com/questions/13593902/node-command-not-found Jan 13, 2014 at 17:50
  • @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. Jan 13, 2014 at 17:53
  • 2
    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). Jan 13, 2014 at 21:16
  • Are you sure that you are looking for node and not nodejs? node is not what you think it is.
    – Braiam
    Jan 13, 2014 at 22:49
  • @Braiam node is used in every tutorial I've seen Jan 14, 2014 at 8:45

7 Answers 7

50

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.

5
  • I have the same problem, sudo apt-get install npm and then following @jlouzado recomendation complete the job. Now is working well
    – user615274
    Nov 30, 2015 at 19:22
  • 5
    Funny tip: there is a nodejs-legacy package that provides the symlink, purportedly for compatibility with "legacy code" that still relies on it.
    – Simón
    Mar 24, 2016 at 21:51
  • 1
    @Simón I think it's a better solution than making a symbolic link.
    – grooveplex
    May 27, 2016 at 13:00
  • 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.
    – sudo
    Apr 6, 2018 at 23:56
  • 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.
    – Vinayak
    Mar 21, 2019 at 6:43
45

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
2
  • 4
    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. Jan 14, 2014 at 8:47
  • 2
    Installing the nodejs-legacy package lets you use either node or nodejs.
    – grooveplex
    May 27, 2016 at 12:54
26

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.

2
  • 2
    It works. I think this is better than @jlouzado's answer.
    – Shawn Xie
    Jun 15, 2016 at 7:36
  • unless you frequently "start from scratch" with your OS install .... MUCH better to let apt manage symlinks in bin. Thanks! Nov 12, 2017 at 23:14
2

Try this

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

sudo apt-get install -y nodejs

:)

3
  • 2
    Why are you not installing the latest version?: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    – karel
    Jul 29, 2017 at 10:43
  • setup_6.x is stable Jul 31, 2017 at 8:15
  • 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/…
    – karel
    Jul 31, 2017 at 8:29
1

may you need to install manually

sudo apt-get install npm
1
  • 1
    I read everywhere that I shouldn't install npm manually because it was included in > v0.10 :/ I'm a little lost Jan 13, 2014 at 17:57
0

A quick fix for nvm users. I use nvm (node version manager) and for me to use the npm command I must always issue before npm this command nvm use 0.x (replace 0.x with 0.11 or 0.10 for example, the version you wish to use).

0
0

As minerz029 has already mentioned, certain versions of the nodejs package won't provide the node binary due to another package previously using that name. The solution is as simple as following the installatoin steps on Node's own website:

Installing Node.js via package manager | Debian and Ubuntu based Linux distributions

At the moment, those steps are:

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

But it'd be best to check the source link to make sure you're using the latest version.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .