177

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)

Shadi
  • 2,015

9 Answers9

206

I had an issue with the apk manager.

The package nodejs is no longer installing NPM (see pkgs.alpinelinux.org) You have to install npm:

apk add --update nodejs npm
slhck
  • 235,242
206

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.

Ruslan Isay
  • 2,176
31

I could be wrong, but I think npm is actually a dependency of nodejs.

I've never seen any flavor of package manager install npm alone. Always seems to come packaged with yum install nodejs, or apt-get install nodejs, or apk add --update nodejs.

10

apk update && apk add nodejs installed the npm binary for me.

John Delaney
  • 101
  • 1
  • 2
6

The issue here is a recent one and is due to changes in Alpine's package repositories between v3.5 and v3.6 or edge.

In v3.5 nodejs included npm In v3.6 nodesjs does not include npm and the new nodejs-npm package exists.

See here for Alpine packages. To see what version of packages you are pulling from look at the contents of /etc/apk/repositories

Peter
  • 61
4

I could successfully install nodejs and npm in alpine Linux with the below commands. Added benefit for this method is we can choose different node version with nvm

apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

export NVM_DIR="$HOME/.nvm"

[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

nvm install -s <version>

For reference visit here

3

npm comes hand in hand with nodejs. In the case you cant install node with apk add nodejs, you need fix that first. Step 1 - do you have the community repo added to your /etc/apk/repositories list? If not, it is very useful to do so. Further details: https://wiki.alpinelinux.org/wiki/Enable_Community_Repository

vizmi
  • 139
3

I have just had to this and can confirm that npm is not a dependency of node.js (at least right now on alpine) and must be installed seperately

i.e apk add --update npm

2

I needed latest/current node (v20 at time of writing), but right now I only see node v18 on https://pkgs.alpinelinux.org/packages?name=nodejs&branch=edge&repo=&arch=&maintainer= screenshot of the link

However, digging around nodejs.org download options, I found this:

apk add --update nodejs-current npm

screenshot of nodejs.org

NOTE: nodejs-current doesn't seem to include npm, so I needed to add npm to end of the command.