node: command not found

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?


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.


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

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.


Try this

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

sudo apt-get install -y nodejs

:)


may you need to install manually

sudo apt-get install npm