Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RVM: Permission denied while loading gemset from .rvmrc file in system-wide install

Tags:

ruby

vagrant

rvm

I have created a project specific .rvmrc file that includes a custom gemset (using the command rvm --rvmrc --create 1.9.2@registration):

# excerpt of .rvmrc...

environment_id="ruby-1.9.2@registration"

if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
  && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
  \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"

  if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
  then
    . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
  fi
else
  # If the environment file has not yet been created, use the RVM CLI to select.
  if ! rvm --create  "$environment_id"
  then
    echo "Failed to create RVM environment '${environment_id}'."
    return 1
  fi
fi

This works locally on my Mac, using single-user RVM. We are also using Vagrant with a system-wide RVM install on our Vagrant box. However, when we cd into the project directory and accept the .rvmrc file, it results in the following message (yes, there are a lot of duplicate error messages):

mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.2-p318@registration': Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
-bash: /usr/local/rvm/environments/ruby-1.9.2-p318@registration: Permission denied
mkdir: cannot create directory `/usr/local/rvm/wrappers/ruby-1.9.2-p318@registration': Permission denied

Trying to create the gemset manually mentions the same error, but also mentions that it was successful:

$ rvm use 1.9.2
Using /usr/local/rvm/gems/ruby-1.9.2-p318
$ rvm gemset create registration
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.2-p318@registration': Permission denied
'registration' gemset created (/usr/local/rvm/gems/ruby-1.9.2-p318@registration).

Do I have something configured incorrectly? How can I resolve this issue so I can use a custom gemset from an .rvmrc file?

like image 250
Andrew Avatar asked Mar 15 '12 17:03

Andrew


2 Answers

The problem turned out to be that the simple Chef recipe I was using was not adding the vagrant user to the rvm group. This could be accomplished by doing this:

sudo usermod -a -G rvm vagrant

But I decided to switch to a more robust RVM Chef cookbook which worked perfectly using these recipes:

include_recipe "rvm::system"
include_recipe "rvm::vagrant"
like image 158
Andrew Avatar answered Oct 08 '22 16:10

Andrew


Try adding 'sudo' before your rvm commands. ruby@registration will be installed system-wide yet should still work on a per-user basis.

like image 20
martyn Avatar answered Oct 08 '22 15:10

martyn