/bin/sh: npm: command not found
13,784
Your $NODE_VERSION
variable has value 6
as defined in the Dockerfile
(ENV NODE_VERSION 6
) but it should be 6.13.0
so that the following line may work properly:
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
(mapping to /usr/local/nvm/versions/node/v6.13.0/bin
)
Otherwise, you are actually generating the following (wrong) path:
/usr/local/nvm/versions/node/v6/bin
Author by
SlickTester
Updated on June 25, 2022Comments
-
SlickTester almost 2 years
I am creating a docker image for stf.installing nodejs directly using apt-get install nodejs,had many issues.So i decided to go the nvm way.but after installation RUN npm install fails I am building the docker image with su username docker build ..
make sure apt is up to date RUN apt-get update --fix-missing RUN apt-get install -y curl RUN sudo apt-get install -y build-essential libssl-dev ENV NVM_DIR /usr/local/nvm ENV NODE_VERSION 6 # Install nvm with node and npm RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash \ && source $NVM_DIR/nvm.sh \ && nvm install $NODE_VERSION \ && nvm alias default $NODE_VERSION \ && nvm use default ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH #WORKDIR /usr/app # Install app dependencies RUN npm install
and the output
=> Downloading nvm from git to '/usr/local/nvm' => Cloning into '/usr/local/nvm'... * (HEAD detached at v0.30.1) master => Appending source string to /root/.bashrc => Close and reopen your terminal to start using nvm Downloading https://nodejs.org/dist/v6.13.0/node-v6.13.0-linux-x64.tar.xz... ######################################################################## 100.0% WARNING: checksums are currently disabled for node.js v4.0 and later Now using node v6.13.0 (npm v3.10.10) default -> 6 (-> v6.13.0) Now using node v6.13.0 (npm v3.10.10) Removing intermediate container eb9cb6c46f34 ---> eeef6bf9f0f1 Step 38/52 : ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules ---> Running in 185bef8e530c Removing intermediate container 185bef8e530c ---> 0e5bf7b1cfd9 Step 39/52 : ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH ---> Running in 00d58493e199 Removing intermediate container 00d58493e199 ---> 81ed9823020b Step 40/52 : RUN npm install ---> Running in 1c7577133e24 /bin/sh: npm: command not found The command '/bin/sh -c npm install' returned a non-zero code: 127
Please Help.Thanks
Ran the container and checked NPM path
root@69e513b99e68:/home/mobile/MobileFarmDocker# echo $PATH /usr/local/nvm/versions/node/v6.13.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin root@69e513b99e68:/home/mobile/MobileFarmDocker# which npm /usr/local/nvm/versions/node/v6.13.0/bin/npm