Linux – How to install npm in alpine linux

alpine-linuxlinux

So I can't get to install npm in alpine linux. I thought perhaps I can just do a apk add npm but apparently apk search npm returns nothing, even after a apk update. I'm experimenting with all this from the nginx:alpine docker image, i.e. docker run -it nginx:alpine /bin/sh

Edit 1: I can see how the nodejs:alpine dockerfile builds node, but I don't understand how it builds npm

Edit 2: now that I know that npm gets installed with nodejs on alpine, and just for clarification, the reason this wasn't evident to me at first is that on ubuntu 14.04 a sudo apt-get install nodejs would still require a sudo apt-get install npm (which installs development packages e.g. gcc)

Best Answer

For the recent versions of Alpine (v3.8+) the correct way to install nodejs with npm is:

apk add --update nodejs npm

However, npm package depends on nodejs, so you can do:

apk add --update npm

Note: since Alpine 3.8 there is no nodejs-npm package.