52

I am in the process of setting up node.js in order to work with a framework like Meteor, Derby, or Ember, but am running into some problems early on. Following these instructions (http://www.nodebeginner.org), I installed node, created a simple helloworld.js file, then ran this command in the terminal:

node path/to/file/helloworld.js

but I get the following error:

-bash: node: command not found

I've tried navigating to the directory, then simply running:

node helloworld.js

but get the same error. I am completely new to node.js and am at a loss.

Running OS X 10.7.5 and the latest version of node.

Alex Getty
  • 1,687
  • 5
  • 18
  • 20
  • 3
    Try `/usr/local/bin/node path/to/file.js`. – maerics Nov 27 '12 at 22:00
  • 3
    on debian testing right now, the command is nodejs. There is no node binary. –  Feb 25 '15 at 23:06
  • I was trying to use `node -v` in Debian 8 as referred to in an installation guide I was following and was getting the `bash: node: command not found` . Taking a look in `/usr/bin/` showed that it was installed as `nodejs` and so `nodejs -v` has worked for me. – phoenixlaef Sep 12 '15 at 13:57
  • 9
    Try `nodejs helloworld.js`. If you want to use `node` instead of `nodejs`, install `nodejs-legacy` by `sudo apt-get install nodejs-legacy` – Chemical Programmer Nov 27 '15 at 07:49

1 Answers1

57

The problem is that your PATH does not include the location of the node executable.

You can likely run node as "/usr/local/bin/node".

You can add that location to your path by running the following command to add a single line to your bashrc file:

echo 'export PATH=$PATH:/usr/local/bin' >> $HOME/.bashrc
source $HOME/.bashrc
ntg
  • 12,950
  • 7
  • 74
  • 95
maerics
  • 151,642
  • 46
  • 269
  • 291
  • 7
    I am having the same issue. I used the .pkg from the node.js website to install. The installation runs successfully but the command fails to run on Terminal. Turns out that node is not installed at all. Doing `cd` into the installation directory showed that the node installation was not there. The PATH is not the issue in my case. – kRiZ Jan 04 '15 at 01:20
  • 4
    `node` won't be there if u install via `nvm` – Stiger Jul 21 '16 at 05:44
  • 2
    So, where is it if you installed with nvm? I'm getting this error when installing `ng` cli tools after installing node with nvm. – activedecay Nov 11 '19 at 21:59
  • In my case (with ZSH), it was: echo 'export PATH=$PATH:/usr/local/bin' >>$HOME/.zshrc ...and then I ran: source ~/.zshrc – Mike Dubs Nov 13 '19 at 16:16
  • just check your node --version first once you have that run cmd/shell as admin then specify the node version you want your system to use by executing nvm node E.g nvm node 14.15.1 – Code-V Sep 29 '22 at 11:09
  • You can type `nvm root` to check the path to the node version nvm is using. – Darren Evans Apr 18 '23 at 15:01