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?

  • may this post solve your problem Stackoverflow – Ahmed Al-battashi Jan 13 '14 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. – Matthieu Napoli Jan 13 '14 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). – Yong Jie Wong Jan 13 '14 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 '14 at 22:49
  • @Braiam node is used in every tutorial I've seen – Matthieu Napoli Jan 14 '14 at 08:45
  • 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. – binki May 08 '17 at 18:44

7 Answers7

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.

jlouzado
  • 645
  • 5
  • 9
  • 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 '15 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 '16 at 21:51
  • 1
    @Simón I think it's a better solution than making a symbolic link. – grooveplex May 27 '16 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 06 '18 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 '19 at 06: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
kiri
  • 28,246
  • 16
  • 81
  • 118
  • 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. – Matthieu Napoli Jan 14 '14 at 08:47
  • 2
    Installing the nodejs-legacy package lets you use either node or nodejs. – grooveplex May 27 '16 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.

F.Raab
  • 421
  • 4
  • 6
2

Try this

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

sudo apt-get install -y nodejs

:)

Thomas
  • 6,223
MUHASIN BABU
  • 121
  • 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 '17 at 10:43
  • setup_6.x is stable – MUHASIN BABU Jul 31 '17 at 08: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: https://askubuntu.com/questions/626383/node-package-manager-got-corrupted-in-some-way-now-it-cannot-be-installed/626388#626388 – karel Jul 31 '17 at 08:29
1

may you need to install manually

sudo apt-get install npm
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).

David Foerster
  • 36,264
  • 56
  • 94
  • 147
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.

bmaupin
  • 4,930