I am using Vagrant + VirtualBox to set up a virtual machine for my Rails app. I am working on cleaning up a .sh
provisioning script that is referenced in
I had a similar problem because I was trying to install rbenv and the vagrant provisioning was giving me the error:
==> default: /tmp/vagrant-shell: line 10: rbenv: command not found
First of all, it is very important to understand that vagrant provisioning script is running in sudo mode. So, when in the script we refer to ~/ path, we are referring to /root/ path and not to /home/vagrant/ path. The problem is that I was installing rbenv for the root user and after trying to call rbenv command from a vagrant user and, of course, it didn't work!
So, what I did is specify the vagrant to run the provisioner NOT in sudo user, adding privileged: false:
config.vm.provision :shell, privileged: false, inline: $script
Then in my script I considered everything as being called from the vagrant user. Here @Casper answer helped me a lot, because it works only specifying: sudo -H -u vagrant bash -i -c '......'
Since you just updated .bashrc with a new path and other settings, you will want to run "sudo bash" with the -i option. This will force bash to simulate an interactive login shell, and therefore read .bashrc and load the correct path for rbenv.
Below is my final Vagrantfile.
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <