DEV Community

Cover image for Installing NPM with Docker
Lukas Hron
Lukas Hron

Posted on

Installing NPM with Docker

How to install NPM into my custom Docker container? We will show three basic ways in DockerFile.

First and simple way

FROM debian:11-slim RUN apt-get update && apt-get install -y wget gnupg g++ apt-utils curl git && apt-get clean ###################### RUN apt-get update && apt-get install -y npm && apt-get clean 
Enter fullscreen mode Exit fullscreen mode

Installing with NVM tool

FROM debian:11-slim RUN apt-get update && apt-get install -y wget gnupg g++ apt-utils curl git && apt-get clean ###################### ENV NODE_VERSION 20.12.2 ENV NVM_DIR /usr/local/nvm RUN mkdir -p $NVM_DIR RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash RUN . "${NVM_DIR}/nvm.sh" \ && nvm install $NODE_VERSION \ && nvm alias default $NODE_VERSION \ && nvm use $NODE_VERSION ENV PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:${PATH}" 
Enter fullscreen mode Exit fullscreen mode

Installing from Debian Nodesource resources

FROM debian:11-slim RUN apt-get update && apt-get install -y wget gnupg g++ apt-utils curl git && apt-get clean ###################### RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \ && apt-get update && apt-get install -y nodejs \ && apt-get clean 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)