Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to install /usr/bin/npm with Docker

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
$

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading