使用RVM环境运行bash的问题

时间:2013-09-13 03:18:40

标签: ruby-on-rails ruby bash deployment rvm

我正在使用whiskey_disk来处理部署。这不是威士忌_disk问题,但它的作用是在完成从git克隆到项目目标目录后运行后部署脚本。我正在尝试部署的脚本是调用bundle install并看起来像这样:

#!/bin/bash

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  source "/usr/local/rvm/scripts/rvm"
else
  printf "ERROR: An RVM installation was not found.\n"
fi

export PATH=/home/ec2-user/.rvm/gems/ruby-2.0.0-p247/bin:/home/ec2-user/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/bin:/home/ec2-user/.rvm/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin

echo "["`hostname`"] Installing the bundle..."
bundle install --binstubs --local --path ../shared/bundle --deployment --without development test console replication|grep -vi using

失败,但无法找到bundlerake,即使它已在上面$PATH中明确设置:

/home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'bundler' (>= 0) among 90 total gem(s) (Gem::LoadError)
    from /home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247@global/bin/bundle:22:in `<main>'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
/home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'rake' (>= 0) among 90 total gem(s) (Gem::LoadError)
    from /home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /home/ec2-user/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:22:in `<main>'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'

我认为我在脚本的开头初始化了环境,并且通过另外设置我可以看到的PATH,使用交互式shell可以看到它很好:

[ec2-user@ip-1 ~]$ which bundle
~/.rvm/gems/ruby-2.0.0-p247@global/bin/bundle
[ec2-user@ip-1 ~]$ which rake
~/.rvm/gems/ruby-2.0.0-p247@global/bin/rake

有关其他问题的任何建议吗?

1 个答案:

答案 0 :(得分:2)

RVM通过更改3个环境变量(最小集合)来工作,仅仅更改PATH是不够的,您还需要更改GEM_HOMEGEM_PATH

最简单的是替换这一行:

export PATH=...

使用:

rvm use 2.0.0

然后RVM进行环境加载,所有都应该正常工作。