Search code examples
node.jslinuxdockerdockerfilealpine-linux

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?


Solution

  • 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