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.
source to share
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
source to share
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:
- Build your Dockerfile on
openjdk:latest
+ install node.js yourself. Just copy a few lines from the official node.js Dockerfile - https://github.com/nodejs/docker-node/blob/master/7.10/wheezy/Dockerfile - Configure your Dockerfile to
node:latest
+ install OpenJDK. Another way. - Use something already built like docker image with openjdk + node - https://hub.docker.com/r/silas/openjdk-node/~/dockerfile/
source to share
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
source to share