How to install nvm in docker?

后端 未结 14 939
陌清茗
陌清茗 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 07:00

    None of these worked for me, for my python3-onbuild container I had to force-create symbolic links to the nvm installation.

    # Install npm and nodejs
    RUN apt-get install -y build-essential libssl-dev
    
    RUN mkdir /root/.nvm
    ENV NVM_DIR /root/.nvm
    ENV NODE_VERSION 8.9.4
    
    RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
    RUN chmod +x $HOME/.nvm/nvm.sh
    RUN . $HOME/.nvm/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default && npm install -g npm
    
    RUN ln -sf /root/.nvm/versions/node/v$NODE_VERSION/bin/node /usr/bin/nodejs
    RUN ln -sf /root/.nvm/versions/node/v$NODE_VERSION/bin/node /usr/bin/node
    RUN ln -sf /root/.nvm/versions/node/v$NODE_VERSION/bin/npm /usr/bin/npm
    
    0 讨论(0)
  • 2020-12-04 07:00

    This is what worked for me (I'm using debian buster):

    RUN apt-get update
    RUN apt-get install -y build-essential checkinstall libssl-dev
    RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.1/install.sh | bash
    SHELL ["/bin/bash", "--login", "-c"]
    

    You should now be able to do nvm install <version>.

    0 讨论(0)
提交回复
热议问题