Kalanamith
Kalanamith

Reputation: 20648

Error installing nodejs version 12 on alpine linux

I am using the following Dockerfile to install alpine linux as follows and referred the following stack overflow answer :- How to install Nodejs v13.0.1 in alpine:3.8?

FROM alpine:3.9

ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
RUN echo "${ALPINE_MIRROR}/v3.10/community/" >> /etc/apk/repositories
RUN apk update && apk add glibc nodejs-current --repository="http://dl-cdn.alpinelinux.org/alpine/v3.10/community/"
RUN node --version

Node version results an error

Error relocating /usr/bin/node: uv_gettimeofday: symbol not found
Error relocating /usr/bin/node: uv_udp_connect: symbol not found
Error relocating /usr/bin/node: uv_thread_create_ex: symbol not found
Error relocating /usr/bin/node: uv_udp_getpeername: symbol not found
The command '/bin/sh -c node --version' returned a non-zero code: 127

How to fix this and install node 12.4.0-r0?

Upvotes: 4

Views: 15543

Answers (5)

ButterflyRay
ButterflyRay

Reputation: 423

You can do something like this in your Docker file.

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.12/main/ nodejs=12.22.12-r0 npm=12.22.12-r0

You need to pickup the correct repository for the node version you are trying to install. You can find the correct repository, branch etc from here - https://pkgs.alpinelinux.org/packages

Upvotes: 0

4r7if3x
4r7if3x

Reputation: 3591

@Adiii's answer is almost correct, but the version number has to be specified. Otherwise, the latest version would be installed if you are using a newer image. You also don't need the --repository option, since you already have it added to your repositories. This way, you can also add packages from other repositories at the same time. And finally, if you need npm, you should add it separately.

RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main/" >> /etc/apk/repositories \
    && apk add --update nodejs=12.22.12-r0 npm=12.22.12-r0 other-package

Upvotes: 0

Yogesh Kumar
Yogesh Kumar

Reputation: 99

alpine:3.12 now uses node 12.22.10 version

You can check the latest node version based on the alpine version in this link

Upvotes: 0

alturium
alturium

Reputation: 583

alpine:3.12 now uses node v12.22.1

FROM alpine:3.12

RUN node --version

Upvotes: 2

Adiii
Adiii

Reputation: 59916

You should not install nodejs-current, as this package is helpful to install *current version of nodejs from edge repository where nodejs version does not exist.

In your case, nodejs 12.x package already exists so You should install nodejs if you want to install an older version instead of nodejs-current.

FROM alpine:3.9
ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
RUN echo "${ALPINE_MIRROR}/v3.11/main/" >> /etc/apk/repositories
RUN apk add nodejs --repository="http://dl-cdn.alpinelinux.org/alpine/v3.11/main/"
RUN node --version

output

Removing intermediate container a201832610e0
 ---> b0919df78aef
Step 5/5 : RUN node --version
 ---> Running in cd7950f9303b
v12.15.0
Removing intermediate container cd7950f9303b
 ---> ce54af976f81
Successfully built ce54af976f81

Upvotes: 9

Related Questions