node.jsvagrantnvmubuntu-13.04

Node is installed during provisioning on vagrant but disappears upon connecting to ssh


I am really getting sick of this and I don't know what is wrong. I am using Vagrant 1.7.2 , Ubuntu 13.04 , Virtual Box 4.3 12 r93733

My host machine is Windows 8.1

Here is my node bootstrap script found on my bootstrap.sh

echo "--- Installing Node.js ---"
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | bash
source ~/.nvm/nvm.sh
nvm install 0.12
nvm use 0.12
sudo cp ~/.nvm/versions/nodejs/v0.12/bin/node /bin/node

echo "--- Install node app dependencies --"
cd /var/www/html/node
npm install express
npm install youtube-audio-stream

During provisioning I could see that node is installed correctly . I could see the Now using node v0.12 . I could also see that the npm install's are successful

However when I connect using vagrant ssh . I get No command 'nvm' found . And The program 'node' can be found in the following packages: . I also checked ~/.nvm/ directory, it is not existing.

It becomes even weirder. So while I'm at ssh, I rerun the script again. Then nvm is now correctly installed and I could use node.


Solution

  • This is what I came up with

    echo "--- Installing Node.js ---"
    git clone https://github.com/creationix/nvm.git /home/vagrant/.nvm && cd /home/vagrant/.nvm && git checkout `git describe --abbrev=0 --tags`
    source /home/vagrant/.nvm/nvm.sh
    nvm install 0.12
    nvm use 0.12
    n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local