distributions: [ERROR] Node.js 16.x on Debian Bookworm Installation fail

Before we come to the bug, thank you very much for this project!

Describe your bug Installing NodeJS 16 on Debian Bookworm gives npm: command not found.

Distribution Information:

  • OS: Debian
  • Version: Bookworm
  • Docker image: debian:bookworm-20230703

Node Version:

  • Node: v16.x

To Reproduce Steps to reproduce the behavior:

  1. Install Debian Bookworm: docker run -ti --rm debian:bookworm-20230703 /bin/bash
  2. Install Node.js v16.x using following instructions:
apt-get update && \
    apt-get install -y curl

curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
    apt-get install -y nodejs && \
    npm update

Expected behavior npm is correctly installed. Instead

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Same works on debian:bullseye.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

@lightswitch05

This seems to be the same issue as before. You have to pin deb.nodesource.com first. Just an example:

docker build --no-cache --progress=plain -t test-node-install:local -f- . <<EOF
FROM debian:bookworm-slim
WORKDIR /app
RUN apt-get update \
    && apt-get install -y ca-certificates curl gnupg \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
    && echo "Package: nodejs" >> /etc/apt/preferences.d/preferences \
    && echo "Pin: origin deb.nodesource.com" >> /etc/apt/preferences.d/preferences \
    && echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/preferences\
    && apt-get update \
    && apt-get install -y nodejs

RUN npm install lodash
EOF

This issue is resolved with our new repository. More information can be found here.

I had the same issue with node_20

it was indeed fixed with

RUN echo "Package: nodejs" >> /etc/apt/preferences.d/preferences \
    && echo "Pin: origin deb.nodesource.com" >> /etc/apt/preferences.d/preferences \
    && echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/preferences

This only works with app resources.


RUN mkdir -p /etc/apt/keyrings && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Could you also add this update the setup files like https://deb.nodesource.com/setup_20.x because it’s now installing a different version ?

In my case it was installing version 18 instead of 20

Hello @JesusPaz @o1y - using the new repository does not fix this issue. Also, it is trivial to reproduce with a simple copy/paste command:

docker pull debian:bookworm-slim
docker build --progress=plain -t test-node-install:local -f- . <<EOF
FROM debian:bookworm-slim
RUN apt-get update \
    && apt-get install -y ca-certificates curl gnupg \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
    && apt-get update \
    && apt-get install -y nodejs
RUN npm install lodash
EOF

Node appears to install correctly - using the commands specificed by the new repository. However, the final npm install command fails with the same error this issue was opened with:

/bin/sh: 1: npm: not found

Its also interesting that the same error occurs with node 18. Also using debian bullseye. It just seems NPM is never installed using this method. Is that the expectation?

We will check it out and let you know if we have any news.

@JesusPaz Any updates?

Actually, I would like to update my comment about bullseye - maybe something was going on with cache - but this works successfully with bullseye.

docker build --no-cache --progress=plain -t test-node-install:local -f- . <<EOF
FROM debian:bullseye-slim
WORKDIR /app
RUN apt-get update \
    && apt-get install -y ca-certificates curl gnupg \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
    && apt-get update \
    && apt-get install -y nodejs
RUN npm install lodash
EOF

The exact same commend with bullseye switched out to bookworm fails:

docker build --no-cache --progress=plain -t test-node-install:local -f- . <<EOF
FROM debian:bookworm-slim
WORKDIR /app
RUN apt-get update \
    && apt-get install -y ca-certificates curl gnupg \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
    && apt-get update \
    && apt-get install -y nodejs
RUN npm install lodash
EOF

We will check it out and let you know if we have any news.

Same here !

Our dockerfile looks like (NODE_VERSION=16):

RUN apt-get update \
    && curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm

and we get the same error: “npm not found”

As we work with php 8,1 we changed the node version to 18.x and it works.