8
votes

I've just installed nodejs on Debian 7 - by apt-get install nodejs.

Nodejs seems to be working fine, but when I enter "npm" I get "command not found".

"which nodejs" points to "usr/bin" and there it is - nodejs, but there is no npm file, what went wrong?

I found a few solutions, but all of them are related to Macs

BTW, "usr/local/bin" directory is empty I believe everything should install right there?

5
Now, both github and npm are owned by M$. No worries; Debian is next. j/k - Lonnie Best

5 Answers

10
votes

You have several options.

If you want to continue using Debian packages, you could install npm (debian maintainers have it in a separate package).

apt-get install npm

If you want to just install npm, you can use this modification of Maxime's answer:

curl -L https://npmjs.org/install.sh | sudo sh

(the -L is needed to make curl follow redirects.)

Finally, you may wish to use a different package source. For some Linux distributions (Debian/Ubuntu and RedHat/CentOS), the latest node version provided by the distribution may lag behind the stable version. Here are instructions from NodeSource on getting the latest node, which includes npm and avoids using the problematic nodejs alias

7
votes

Install npm

curl -L https://npmjs.org/install.sh | sudo sh

(the -L is needed to make curl follow redirects.)

and check version

npm -v
1
votes

Node.js is easy to install in Linux

  1. create a directory nodejs inside /usr/local/lib
  2. download nodejs

    • move downloaded tar.xz file inside /usr/local/lib
    • extract the tar.xz file and rename as like node-v8.9.4
  3. setup environment

    cd ./etc/profile.d ls sudo touch nodejs-env.sh sudo atom nodejs-env.sh where atom is my favourite editor; you can use your editor.

  4. copy and paste below code inside nodejs-env.sh and save

    export NODEJS_HOME=/usr/local/lib/nodejs/node-v8.9.4 export PATH=$NODEJS_HOME/bin:$PATH

  5. restart you machine.
  6. done
0
votes

There were several methods to install node.js on your debian. But I prefer this one:

Setup with Debian (as root):

apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -

Then install with Debian (as root):

apt-get install --yes nodejs

After that, relaunch your terminal and type "npm" in your terminal.

0
votes

The problem you're facing is due the need of super user rights during the installation. As others mentioned, you could do it via the sudo command and the manual installer.

Either way, there're several ways to install node in *unix platforms in a safer way without the need of super user rights using NVM (Node Version Manager).

Steps:

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash

$ nvm install 0.10

Also, you can find different techniques to install node and npm without having to sudo.