<p>The issue is that <code>prereqs-ubuntu.sh</code> uses <code>bash</code> to install the <code>npm</code>. While the <code>RUN</code> directive uses <code>sh</code> to run the commands. </p>

<p>Where is the npm installed</p>

<pre><code>root@2cd4a6af90f4:/app# type npm
npm is /root/.nvm/versions/node/v8.16.0/bin/npm
</code></pre>

<p>The <code>PATH</code> for the <code>RUN</code> directive</p>

<pre><code># echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
</code></pre>

CC BY-SA 4.0
2021-08-02T00:13:56.913Z
Thanks but how does one fix this? I am on MacOS trying to run my Node app on docker.
philosopher
CC BY-SA 4.0
2019-07-08T07:05:22.463Z
2019-07-08T07:05:22.463Z
Yuri G.
<p>I have a following Dockerfile:</p>

<pre><code>FROM ubuntu:18.04

RUN mkdir app &amp;&amp; cd app
WORKDIR app/

RUN apt-get update &amp;&amp; apt-get install -y \
    software-properties-common \
    curl \
    sudo \
    &amp;&amp; curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh \
    &amp;&amp; chmod u+x prereqs-ubuntu.sh \
    &amp;&amp; ./prereqs-ubuntu.sh \
    &amp;&amp; npm install -g \ # this line failed
    &amp;&amp; yo \
       composer-cli@0.20 \
       composer-rest-server@0.20 \
       generator-hyperledger-composer@0.20 \
       composer-playground@0.20

    CMD /bin/bash
</code></pre>

<p>The <code>prereqs-ubuntu.sh</code> is from <a href="https://github.com/hyperledger/composer/blob/master/packages/composer-website/jekylldocs/prereqs-ubuntu.sh" rel="nofollow noreferrer">https://github.com/hyperledger/composer/blob/master/packages/composer-website/jekylldocs/prereqs-ubuntu.sh</a>.</p>

<p>However, it says <code>/bin/sh: 1: npm: not found</code> on the line <code>npm install -g</code> when I try to build the image. But <code>npm</code> is installed when running <code>prereqs-ubuntu.sh</code> already and can be ran successfully at the end of the file (<code>npm --version</code>).</p>

<p>Also, when I remove the <code>npm-install</code> part from the Dockerfile (shown below) and do <code>docker run --name test -it myimage</code> to see if <code>npm</code> is installed, but it is installed.</p>

<pre><code>FROM ubuntu:18.04

RUN mkdir app &amp;&amp; cd app
WORKDIR app/

RUN apt-get update &amp;&amp; apt-get install -y \
    software-properties-common \
    curl \
    sudo \
    &amp;&amp; curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh \
    &amp;&amp; chmod u+x prereqs-ubuntu.sh \
    &amp;&amp; ./prereqs-ubuntu.sh \

    CMD /bin/bash
</code></pre>

<docker><dockerfile><shell-script><bash><npm>
npm not found but installed from the shell script file in Dockerfile
Leon Ma
# npm not found but installed from the shell script file in Dockerfile

(Asked by: username_0 on 2019-07-07)

I have a following Dockerfile:
FROM ubuntu:18.04

RUN mkdir app && cd app
WORKDIR app/

RUN apt-get update && apt-get install -y \
    software-properties-common \
    curl \
    sudo \
    && curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh \
    && chmod u+x prereqs-ubuntu.sh \
    && ./prereqs-ubuntu.sh \
    && npm install -g \ # this line failed
    && yo \
       composer-cli@0.20 \
       composer-rest-server@0.20 \
       generator-hyperledger-composer@0.20 \
       composer-playground@0.20

    CMD /bin/bash

The prereqs-ubuntu.sh is from https://github.com/hyperledger/composer/blob/master/packages/composer-website/jekylldocs/prereqs-ubuntu.sh.
However, it says /bin/sh: 1: npm: not found on the line npm install -g when I try to build the image. But npm is installed when running prereqs-ubuntu.sh already and can be ran successfully at the end of the file (npm --version).
Also, when I remove the npm-install part from the Dockerfile (shown below) and do docker run --name test -it myimage to see if npm is installed, but it is installed.
FROM ubuntu:18.04

RUN mkdir app && cd app
WORKDIR app/

RUN apt-get update && apt-get install -y \
    software-properties-common \
    curl \
    sudo \
    && curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh \
    && chmod u+x prereqs-ubuntu.sh \
    && ./prereqs-ubuntu.sh \

    CMD /bin/bash

**Tags:** docker, dockerfile, shell-script, bash, npm


---

## 1 answers

### Answer by username_1 on 2019-07-08. Score: 3 | Accepted answer

The issue is that prereqs-ubuntu.sh uses bash to install the npm. While the RUN directive uses sh to run the commands. 
Where is the npm installed
root@2cd4a6af90f4:/app# type npm
npm is /root/.nvm/versions/node/v8.16.0/bin/npm

The PATH for the RUN directive
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

> **Comments:**
> **username_2**: Thanks but how does one fix this? I am on MacOS trying to run my Node app on docker.  

---

