Vagrant/VirtualBox VM provisioning: rbenv installs successfully but subsequent uses in script fail

前端 未结 3 970
南笙
南笙 2020-12-25 08:56

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

3条回答
  •  天涯浪人
    2020-12-25 09:29

    I'm surprised the provisioning script exits, as running su vagrant should in theory hang the script at that point (you're running the command su which does not normally exit by itself).

    The problem is you cannot change the user that is running a shell script "on the fly" by running su.
    Your only option is to use sudo.

    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.

    So, something like this should hopefully work:

    echo "building ruby"
    sudo -H -u vagrant bash -i -c 'rbenv install 2.2.1 ...'
    

提交回复
热议问题