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

心已入冬 提交于 2019-12-13 17:53:06

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/28684471/node-is-installed-during-provisioning-on-vagrant-but-disappears-upon-connecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!