Npm command not available in Docker container

I am using this:

RUN sudo apt-get install -y nodejs

      

and then we link the nodejs executable to node like this:

RUN sudo ln -s `which nodejs` /usr/bin/node

      

which is all well and good, but for some reason the "npm" command is not available after installing nodejs.

What was it for? I thought npm is always bundled with nodejs? What do I need to do to install npm? I'm sure nodejs is installed, but npm doesn't seem to be present, $(which npm)

gives nothing.

+3


source to share


3 answers


If you are using my solution from here (and it really looks like you), then you should know that the Java image is based on Debian Jessie .



If you look at Jesse's packages, you will see that Jesse has npm

as a separate package

+3


source


So, as you mentioned, your docker background image is openjdk:latest

Not surprisingly, apt-get install nodejs

it installs version 0.10 on startup . Since then, what's available in the Debian repos at the time. And as @nordenheim correctly pointed out - npm was not included in the node.js distribution.

So, based on your comments, it looks like you want to install a fresh node.js like 7.x.



You have 3 options:

enter image description here

+2


source


it might be a documentation error:

https://nodejs.org/en/download/package-manager/

is like installing npm along with nodejs, we need to use:

 sudo apt-get install -y nodejs npm

      

this is

  • a bit surprising (although it's good that npm is now decoupled from nodejs)
  • now there are a lot more depots installed, which sucks
+1


source







All Articles