简体   繁体   中英

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?

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

alpine:3.12 now uses node v12.22.1

FROM alpine:3.12

RUN node --version

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

@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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM