11

So, I'm working on a mac and as webserver, I got Debian 8 installed. However, I'm currently working on a node application which I developed on my localhost most of the time, where everything works fine - I can use node index.js without issues.

However, I installed node on my webserver via the recommendation of the node.js website, which is ...

sudo apt-get install -y nodejs

... which didn't throw any errors. After that, I could use the npm command. But when I try to execute node index.js, I receive bash: node: command not found. Also, node is not installed in my /usr/local/bin folder. So I can't even run in via /usr/local/bin/node which was recommended here.

So what exactly did I do wrong? I'm rather confused right now and really don't know how to fix the problem.

Community
  • 1
  • 1
Realitätsverlust
  • 3,941
  • 2
  • 22
  • 46

4 Answers4

18

Did you previously install node package, too? If so, try:

$ sudo apt-get --purge remove node
$ sudo apt-get --purge remove nodejs
$ sudo apt-get install -y nodejs-legacy

# check
$ node --version
v4.0.0

See also this answer

Community
  • 1
  • 1
MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • Didn't work for me. However, when i purge everything and install nodejs-legacy, it works fine. Tyvm :) – Realitätsverlust Apr 27 '16 at 07:33
  • Yes, I did read about `nodejs-legacy`... Probably the package has been named that way (on some DEbian version) to avoid conficts with another package named `node`, which is totally unrelated to nodejs... Updated my answer. – MarcoS Apr 27 '16 at 07:39
1

Go to the official Node.js download page and download either the 32-bit or 64-bit Linux binary file, depending on your system type.
You can determine the CPU architecture of your server with these commands:

$ getconf LONG_BIT
64
$ uname -p
x86_64

You can download this file from the browser or from the console. The latter is shown below (Note: the specific Node.js version might be different for you):

$ wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz **Change node version **

From a console window, go to the directory to which the Node.js binary was downloaded, and then execute the following command to install the Node.js binary package in “/usr/local/”:

$ sudo tar -C /usr/local --strip-components 1 -xzf node-v4.2.2-linux-x64.tar.gz

You should now have both node and npm installed in “/usr/local/bin”. You can check this typing:

$ ls -l /usr/local/bin/node
$ ls -l /usr/local/bin/npm

Check node version
$ node -v
$ npm -v

Saurabh
  • 11
  • 5
  • just works. packacge manager was installing node but npm not found. Not sure why. This saved the day. Thanks. however ran copy command afterward cp /usr/local/node /usr/bin, cp /usr/local/npm /usr/bin – user1502826 Nov 08 '17 at 12:31
0

I just installed node on raspian (Debian for Raspberry Pi) and had the same problem. The command nodejs worked for me though.

Matt
  • 201
  • 2
  • 3
0

My problem was that I didn't load the distributions repo...

for the curl url, you'll need to change your setup_#.x number based on your version of Debian.

Adding the NodeSource APT repository for Debian-based distributions repository AND the PGP key for verifying packages

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

Install Node.js from the Debian-based distributions repository

$ sudo apt-get install -y nodejs

Hope this helps!

More information here... http://nodesource.com/blog/installing-node-js-tutorial-debian-linux/

drexel sharp
  • 323
  • 1
  • 9