I suggest you go back to the shell provisioning strategy , I've also went trough hell with this one but is definitely doable.
After a lot of googling I found that there are two very vaguely documented settings you require for this to work:
First and the most important part is that you need to enable the creation of symlinks on the VirtualBox instance with this line on your config.vm.provider
block, without this NVM just won't work (look in here):
config.vm.provider "virtualbox" do |vb|
# (...)
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant","1"]
end
Next you'll have to separate your provisioning script in two parts, one that will run the normal apt/git/whatever stuff as root... and another that will run as the default 'vagrant' user:
$rootScript = <<SCRIPT
# some rooty stuff (just don't forget to include git and curl here)
SCRIPT
## This is the script that will install nvm as the default 'vagrant' user
$userScript = <<SCRIPT
cd /home/vagrant
# 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
nvm alias default 0.10.33
# You can also install other stuff here
npm install -g bower ember-cli
SCRIPT
Last, you need to tell vagrant to run the second script with just user privileges (as almost entirely undocumented here):
config.vm.provision "shell", inline: $rootScript
config.vm.provision "shell", inline: $userScript, privileged: false
That should do. Is not pretty but it works.
Check out this working gist here, and good luck!