nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
80.02k stars 8.01k forks source link

Script fails with ~ in NVM_DIR #2074

Open gv-beemining opened 5 years ago

gv-beemining commented 5 years ago

Docker installation

Create a docker file then install NVM

script is not working with "~" home directory in path

Hi im trying to install NVM in a docker image with

Install nvm with node and npm

RUN mkdir -p ~/.nvm ENV NODE_ENV development ENV NVM_DIR /root/.nvm ENV NODE_VERSION 10.16.0 RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash RUN source $NVM_DIR/nvm.sh \ && nvm install $NODE_VERSION \ && nvm alias default $NODE_VERSION \ && nvm use default 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 RUN npm install pm2 -g RUN npm install nodemon -g

but if i use ENV_NVM_DIR as ~/.nvm it fails with the next error

You have $NVM_DIR set to "~/.nvm", but that directory does not exist. Check your profile files and environment.

ljharb commented 5 years ago

Is $HOME the same as /root?

Separately, there shouldn't be any need to symlink node/npm into /usr/bin; when nvm is used, it's available in the PATH (and nodejs isn't a binary name anyone should ever be using)

gv-beemining commented 5 years ago

yes $HOME is the same as /root

without the symlinks i can't use npm from the dockerfile, it says npm: command not found

ljharb commented 5 years ago

The dockerfile has to source nvm.sh to have nvm working properly.

I'd use $HOME then instead of ~ or /root