RVM:在系统范围的安装中从.rvmrc文件加载gemset时权限被拒绝

时间:2012-03-15 17:13:36

标签: ruby rvm vagrant

我创建了一个项目特定的.rvmrc文件,其中包含一个自定义gemset(使用命令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

这可以在我的Mac上本地使用单用户RVM。我们还使用Vagrant在我们的Vagrant盒子上安装了系统范围的RVM。但是,当我们cd进入项目目录并接受.rvmrc文件时,会产生以下消息(是的,有很多重复的错误消息):

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

尝试手动创建gemset时会提到相同的错误,但也提到它是成功的:

$ 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).

我是否有错误的配置?如何解决此问题,以便我可以使用.rvmrc文件中的自定义gemset?

3 个答案:

答案 0 :(得分:9)

问题原来是我使用的简单厨师食谱没有将流浪者用户添加到rvm组。这可以通过这样做来实现:

sudo usermod -a -G rvm vagrant

但是我决定转用更多robust RVM Chef cookbook,使用这些食谱完美运作:

include_recipe "rvm::system"
include_recipe "rvm::vagrant"

答案 1 :(得分:1)

尝试在'sudo'之前添加rvm commandsruby@registration将在系统范围内安装,但仍应按用户使用。

答案 2 :(得分:0)

对我来说,问题是我在我的主目录(用户安装)中安装了.rvm,但是以某种方式设法让root目录为root:root。

ls -al / home / darren * drwxr-xr-x 2 root root 4096 Oct 18 16:46 .rvm *

sudo chown darren:rvm .rvm -R

sudo useradd darren rvm