skip to Main Content

I have the following Dockerfile. It correctly installs /usr/bin/node but not /usr/bin/npm. What do I need to add/change to fix this?

FROM php:8.3-apache
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN apt-get update && 
    apt-get install -y 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 && 
    NODE_MAJOR=21 && 
    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && 
    apt-get install -y zip mariadb-client libmagickwand-dev chromium nodejs && 
    docker-php-ext-install mysqli pdo pdo_mysql exif && 
    a2enmod headers rewrite
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/chromium"
$ which node
/usr/bin/node
$ which npm
$

2

Answers


  1. You did not run [sudo] apt update after adding nodesource to the keyring.

    apt update && apt-get install -y zip mariadb-client libmagickwand-dev chromium nodejs && 
    ...
    

    This should work. Otherwise try inspecting the $PATH and check if /usr/local/bin is there, if not add it. You last option (which was not necessary for a long time) is to do sudo apt-get install npm.

    Login or Signup to reply.
  2. Another way to install both via the Docker image

    COPY --from=node:20 /usr/local/ /usr/local/
    ENV PATH="/usr/local/bin:${PATH}"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search