How to install nvm in docker?

后端 未结 14 945
陌清茗
陌清茗 2020-12-04 05:53

I am in the process of building a new Docker image and I\'m looking to get NVM installed so I can manage nodejs.

Reading the docs on how to install NVM they mention

14条回答
  •  再見小時候
    2020-12-04 06:51

    This is based on the top answer and works in 2018:

    # Replace shell with bash so we can source files
    RUN rm /bin/sh && ln -s /bin/bash /bin/sh
    
    # Install base dependencies
    RUN apt-get update && apt-get install -y -q --no-install-recommends \
            apt-transport-https \
            build-essential \
            ca-certificates \
            curl \
            git \
            libssl-dev \
            wget
    
    ENV NVM_DIR /usr/local/nvm
    ENV NODE_VERSION 8.11.3
    
    WORKDIR $NVM_DIR
    
    RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash \
        && . $NVM_DIR/nvm.sh \
        && nvm install $NODE_VERSION \
        && nvm alias default $NODE_VERSION \
        && nvm use default
    
    ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
    ENV PATH      $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
    

    Note that nvm is not a bash command, it is an alias. This can screw you up if you're relying on $PATH.

提交回复
热议问题