grailssudogvm

Install grails as another user with sudo


I want to install grails in my vagrant provision bootstrap bash file (which is executed as root). I tried to change the installation like shown on the grails manual:

curl -s get.gvmtool.net | sudo -u vagrant -H bash
sudo -u vagrant -H bash "$HOME/.gvm/bin/gvm-init.sh"
sudo -u vagrant -H bash gvm install grails

But this gives errors:

bash: /root/.gvm/bin/gvm-init.sh: Permission denied
bash: gvm: No such file or directory

what am I doing wrong?


Solution

  • This could work:

    curl -s get.sdkman.io | sudo -u vagrant -H bash -i
    sudo -u vagrant -H bash -i 'source "$HOME/.sdkman/bin/sdkman-init.sh"; sdk install grails'
    

    The -i (simulate initial login) option
    ... This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution.