This code seems to work fine on 'vagrant up', but when I 'vagrant ssh' into the vm I have to redo everything in the "#doesn't take" block, even though I saw the successful output while the scripts were being run.
In Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 9000, host: 9000, auto_correct: true
config.ssh.forward_agent = true
config.vm.synced_folder ".", "/home/vagrant/www", create: true, group: "vagrant", owner: "vagrant"
config.vm.provision :shell, path: "vagrant/rootScript.sh"
config.vm.provision :shell, privileged: false, path: "vagrant/userScript.sh"
end
rootScript.sh:
sudo apt-get update
sudo apt-get install -y git
sudo apt-get install python-software-properties python g++ make
sudo apt-get update
userScript.sh:
cd www
touch test.txt # this is successfully created in the correct folder
whoami # 'vagrant'
echo "${PWD}" # 'home/vagrant/www'
# # Installing nvm
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
# # This enables NVM without a logout/login
export NVM_DIR="/home/vagrant/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
# Install a node and alias
nvm install 0.10.33
# ************** doesn't take **************
nvm use 0.10.33
npm install -g npm@latest
npm install -g bower grunt-cli
npm install
bower install
# *******************************************
whoami # still 'vagrant'
echo "${PWD}" # still 'home/vagrant/www'
Why do these commands need to be re-run in ssh? And is there anything I can do to make them 'take' while running as a script? Driving me nuts. Thanks for the help.
UPDATE -- just discovered that the npm and bower commands DID take -- only command that does not seem to be working in the script is 'nvm use 0.10.33'