4

I use this:

RUN sudo apt-get install -y nodejs

and then we link nodejs executable to node like so:

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

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

Why would that be? I thought npm was always bundled with nodejs? What do I need to do to get npm installed too? I am certain that nodejs is installed, but npm does not appear to be present, $(which npm) yields nothing.

4
  • Using sudo in docker tends to be a bad practice (see docs.docker.com/engine/userguide/eng-image/…) Commented May 3, 2017 at 21:16
  • Which base image do you use? (FROM ...) Commented May 3, 2017 at 21:22
  • Hey Vlad, I am using "FROM openjdk:latest" Commented May 3, 2017 at 21:28
  • LOL by the way, this install Node.js version 0.10, what the heck, Node is on version 7, almost 8 Commented May 3, 2017 at 21:29

3 Answers 3

3

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

If you take a look at Jessie packages, then you will see, that Jessie has npm as a separate package

Sign up to request clarification or add additional context in comments.

1 Comment

Let's mark this answer as solving the issue :) Thanks
2

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

No surprise when you run apt-get install nodejs it installs version 0.10. Since that's what's available in Debian repos at the time. And as @nordenheim correctly pointed - npm wasn't included into node.js distribution.

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

You have 3 options:

  1. Base your Dockerfile on openjdk:latest + install node.js on your own. Just copy a few lines from official node.js Dockerfile - https://github.com/nodejs/docker-node/blob/master/7.10/wheezy/Dockerfile
  2. Base your Dockerfile on node:latest + install OpenJDK. Just another way around.
  3. Use something already built, like docker image with both openjdk + node - https://hub.docker.com/r/silas/openjdk-node/~/dockerfile/

enter image description here

Comments

1

it might be a documentation bug:

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

looks like to install npm along with nodejs, we need to use:

 sudo apt-get install -y nodejs npm

this is

  1. a bit surprising (although it's good that npm is now decoupled from nodejs)
  2. a lot more deps are being installed now, which sucks

2 Comments

Looks like the apt-cache depends nodejs could also answer your question stackoverflow.com/a/22112729/2123530. Thanks to you, I learned an new OPS trick today :)
if you like what you see, give a thumbs up :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.