1

The code for installing node 14 on centos7 is:

RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash -
RUN yum -y install nodejs 

How does it work? The first command downloads the package. Where does it get stored? How does the second command install nodejs from the downloaded package? Thanks.

What is the difference between putting bash and bash -

UPDATE: If someone came to this question searching for installing node in centos7, here is a code snippet that gets the exact version from NodeJS website.

RUN wget https://nodejs.org/download/release/v14.17.0/node-v14.17.0-linux-x64.tar.gz && \
    tar xf node-v14.17.0-linux-x64.tar.gz -C /opt/ && \
    rm node-v14.17.0-linux-x64.tar.gz
ENV PATH=/opt/node-v14.17.0-linux-x64/bin:$PATH
RUN npm config set cache /tmp --global
1
  • Did you download the script that is being fetched by curl to look at it? You can browse to it here. Commented Apr 21, 2022 at 17:11

1 Answer 1

1
  1. It looks like the first curl statement downloads the rpm instructions from the URL.
  2. The bash statement executes those rpm instructions and probably stores the NPM package 14.x in the local RPM registry
  3. The yum install nodejs installs nodejs from the local RPM registry.

The equivalent wget syntax is:

RUN wget -O - https://rpm.nodesource.com/setup_14.x | bash
RUN yum -y install nodejs 

And to download a specific version of NodeJS from the official website, here it is:

RUN wget https://nodejs.org/download/release/v14.17.0/node-v14.17.0-linux-x64.tar.gz && \
    tar xf node-v14.17.0-linux-x64.tar.gz -C /opt/ && \
    rm node-v14.17.0-linux-x64.tar.gz
ENV PATH=/opt/node-v14.17.0-linux-x64/bin:$PATH
RUN npm config set cache /tmp --global

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.