Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RUN npm install get /bin/sh: 1: npm: not found

Tags:

node.js

docker

I would like to run npm install in a separated RUN.

Here is the dockerfile

RUN  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& nvm install node && nvm use node \
&& npm cache clean -f && npm install -g n && n stable && npm install cross-env \
&& npm install \
&& npm run dev

In this case, npm install works

but when I convert it to:

RUN  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& nvm install node && nvm use node \
&& npm cache clean -f && npm install -g n && n stable && npm install cross-env

RUN npm install
RUN npm run dev

it says

/bin/sh: 1: npm: not found

Why ???

like image 969
Juliatzin Avatar asked Mar 15 '18 22:03

Juliatzin


1 Answers

Worked for me: https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a

ENV NODE_VERSION 15.8.0
RUN apt update\
    && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash\
    && . $HOME/.nvm/nvm.sh\
    && nvm install $NODE_VERSION
ENV NODE_PATH /root/.nvm/v$NODE_VERSION/lib/node_modules
ENV PATH /root/.nvm/versions/node/v$NODE_VERSION/bin:$PATH
like image 191
axell-brendow Avatar answered Oct 18 '22 03:10

axell-brendow