0
votes

I'm using the Vagrant box "thdengops/ubuntu-14.04-dev" which comes with: git, openjdk7, docker, gvm (go), nvm (node), rvm (ruby), jenv (java), virtualenv (python) all pre-installed on the box.

I've created a provisioning shell script which attempts to install Ruby 2.5.1 using rvm and then set that as the current ruby version in use. However the provisioning script is failing over saying rvm: command not found. I know it's installed as if I vagrant up without provisioning then I can do it all manually. I'm pretty sure this is some permission thing that I'm doing wrong but I'm quite new to Vagrant and not an expert with bash / linux past the basics at the moment.

Any ideas what I'm doing wrong to cause these errors? I've pasted in the full vagrantfile and provision script below, you should be able to put them through the latest vagrant to reproduce the error.

Vagrantfile:

Vagrant.configure(2) do |config|
  config.vm.box = "thdengops/ubuntu-14.04-dev"

  config.vm.provision "shell", path: "provision.sh"
end

provision.sh

#!/bin/bash
RUBY_VERSION="2.3.1"

apt-get -y update

if ! rvm list rubies ruby | grep ruby-${RUBY_VERSION}; then
  rvm install ${RUBY_VERSION}
fi

rvm --default use ${RUBY_VERSION}

gem install bundler

Errors from the terminal

==> default: /tmp/vagrant-shell: line 6: rvm: command not found
==> default: /tmp/vagrant-shell: line 7: rvm: command not found
==> default: /tmp/vagrant-shell: line 10: rvm: command not found
1

1 Answers

1
votes

most probably the packages have been installed for vagrant user so when you ssh into the box vagrant user will be able to run the command. however provisioning are run by root by default so you would need vagrant to run this provisioning

config.vm.provision "shell", privileged: false, path: "provision.sh"

in this case you will need to make sure you run some commands with sudo such as apt command