Ubuntu: node: command not found



Question:

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?


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

may you need to install manually

sudo apt-get install npm  


Solution:5

Try this

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

:)


Solution:6

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).


Solution:7

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »