Can't use nvm from bash script Can't use nvm from bash script shell shell

Can't use nvm from bash script


if you have nvm running on the main shell, you just need to add:

export NVM_DIR=$HOME/.nvm;source $NVM_DIR/nvm.sh;

in your script


Here is what worked for me.

First install nvm (once and separately) using SSH or console:

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash

Then in your script, loading your profile as follows:

. ~/.nvm/nvm.sh. ~/.profile. ~/.bashrc

And with some luck nvm should become available inside the script.

nvm install 4.4.2

Tada!


Just put this on top of your script:

export NVM_DIR="$HOME/.nvm"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Worked like a charm here.