What is the best way to install latest nodejs with npm on alpine linux

7

3

I am trying to build my own docker container based on alpine linux and I need to add multiple services in that container (yes it is not recommended as best practice but at the moment my org devops is bit behind the curve and demanding a single dockerfile for my custom image).

I was checking this article to find the way to install the latest version of nodejs with npm on alpine linux. However there seems to be no apk add nodejs@6 or something like that provided in this discussion.

Also it appears that alpine linux does not have the latest version of nodejs (v 8.X) in the repository here.

So do I pretty much have to install nodejs from source? But that option is very slower compared to just installing from alpine repo.

EDIT:

adding nodejs-current in dockerfile is giving another problem

Step ... : RUN apk update && apk add nodejs-current

---> Running in e430b4d279e5 fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz fetch http://nl.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz v3.4.6-213-gb6db4bd [http://dl-cdn.alpinelinux.org/alpine/v3.4/main] v3.4.6-160-g14ad2a3 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community] v3.6.0-3765-g46dd4472f4 [http://nl.alpinelinux.org/alpine/edge/testing] OK: 8679 distinct packages available ERROR: unsatisfiable constraints: nodejs-current (missing): required by: world[nodejs-current]

Andy

Posted 2017-09-22T00:04:00.400

Reputation: 195

You know, there's [unix.se] for that. – None – 2017-09-22T02:01:49.027

Well ... the nature of this question is such that it could be posted here also. – Andy – 2017-09-24T01:30:15.963

Answers

16

We provide two nodejs packages:

  • nodejs in main – LTS version,
  • nodejs-current in community – the current version, as its called by upstream.

So if you want the latest version, install nodejs-current by running:

apk add nodejs-current

Currently it’s 7.10.1 in v3.6 (stable branch) or 8.5.0 in edge (unstable/rolling branch).

We don’t use @N suffixes like nodejs@6, it’s not a valid package name.

Jakub Jirutka

Posted 2017-09-22T00:04:00.400

Reputation: 301

I’ve explicitly stated that you should install nodejs-current from Alpine branch v3.6 or edge, but you’re using v3.4 repositories… v3.4 is quite old. And mixing v3.4 with current testing is extremely bad idea btw… – Jakub Jirutka – 2017-09-26T18:48:29.950

Oh OK! In that case, I will have to wait until the standard PHP image I am using (php:7.1.9-fpm-alpine) update their alpine repo to V3.6 (they use V3.4). – Andy – 2017-09-26T19:01:08.660

No, in that case you should stop using such horribly outdated image! Just use base alpine image and install php7-fpm package. – Jakub Jirutka – 2017-09-26T19:02:42.017

2BTW The answer is right, it’s not my fault that you haven’t read it properly, so it’s quite rude to downvote it. – Jakub Jirutka – 2017-09-26T19:05:11.747