无法使用Capistrano和RVM部署Rails应用程序

7

我有一个使用Capistrano部署的Rails应用程序。由于我想使用更新版本的Ruby,因此在服务器上安装了RVM,并将以下内容添加到我的deploy.rb文件中(根据我找到的各种说明):

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_ruby_string, '1.9.2'
set :rvm_type, :user

当我运行cap deploy时,会出现以下情况:
    [staging.example.com] executing command
 ** [out :: staging.example.com] /usr/local/lib/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem bundler (>= 0) (
 ** [out :: staging.example.com] Gem::LoadError)
 ** [out :: staging.example.com] from /usr/local/lib/site_ruby/1.8/rubygems.rb:214:in `activate'
 ** [out :: staging.example.com] from /usr/local/lib/site_ruby/1.8/rubygems.rb:1082:in `gem'
 ** [out :: staging.example.com] from /usr/bin/bundle:18
    command finished in 801ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/example/staging.example.com/releases/20110714180125; true"
    servers: ["staging.example.com"]
    [staging.example.com] executing command
    command finished in 895ms
    failed: "rvm_path=$HOME/.rvm/ /usr/local/bin/rvm-shell '1.9.2' -c 'bundle install --gemfile /home/example/staging.example.com/releases/20110714180125/Gemfile --path /home/example/staging.example.com/shared/bundle --deployment --quiet --without development production'" on staging.example.com

为什么Capistrano使用Ruby 1.8版本?显然我的路径也出了问题。

以下是在staging.example.com上运行rvm info的输出:

ruby-1.9.2-p180:

system:
  uname:       "Linux staging 2.6.39.1-linode34 #1 SMP Tue Jun 21 10:29:24 EDT 2011 i686 GNU/Linux"
  bash:        "/bin/bash => GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)"
  zsh:         " => not installed"

rvm:
  version:      "rvm 1.6.22 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

ruby:
  interpreter:  "ruby"
  version:      "1.9.2p180"
  date:         "2011-02-18"
  platform:     "i686-linux"
  patchlevel:   "2011-02-18 revision 30909"
  full_version: "ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]"

homes:
  gem:          "/home/example/.rvm/gems/ruby-1.9.2-p180"
  ruby:         "/home/example/.rvm/rubies/ruby-1.9.2-p180"

binaries:
  ruby:         "/home/example/.rvm/bin/ruby"
  irb:          "/home/example/.rvm/bin/irb"
  gem:          "/home/example/.rvm/bin/gem"
  rake:         "/home/example/.rvm/bin/rake"

environment:
  PATH:         "/home/example/.rvm/bin:/home/example/.rvm/gems/ruby-1.9.2-p180/bin:/home/example/.rvm/gems/ruby-1.9.2-p180@global/bin:/home/example/.rvm/rubies/ruby-1.9.2-p180/bin:/home/example/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
  GEM_HOME:     "/home/example/.rvm/gems/ruby-1.9.2-p180"
  GEM_PATH:     "/home/example/.rvm/gems/ruby-1.9.2-p180:/home/example/.rvm/gems/ruby-1.9.2-p180@global"
  MY_RUBY_HOME: "/home/example/.rvm/rubies/ruby-1.9.2-p180"
  IRBRC:        "/home/example/.rvm/rubies/ruby-1.9.2-p180/.irbrc"
  RUBYOPT:      ""
  gemset:       ""

1
你的项目是否使用了 .rvmrc 文件?如果是的话,它是否指向正确的 Ruby 版本和 Gemset? - Jimmy Baker
这是我的 .rvmrc 文件中的内容:rvm_gemset_create_on_use_flag=1 rvm_trust_rvmrcs_flag=1 不确定如何让它执行你所建议的操作。 - Devin
非常抱歉回复晚了。.rvmrc文件用于指定您要在此项目中使用哪个ruby和gemset。我通常会像这样创建我的:> echo“rvm 1.9.2@myproject”> .rvmrc现在当我进入该目录时,rvm将自动切换到ruby版本1.9.2并将我的gemset更改为myproject。 - Jimmy Baker
3个回答

3
实际上,rvm-capistrano文档页面上的最新文档说明必须像这样:
# RVM bootstrap: change to your Ruby and GemSet
require 'rvm/capistrano'
set :rvm_ruby_string,  ENV['GEM_HOME'].gsub(/.*\//,"")
set :rvm_type, :user

2
失败: "rvm_path=$HOME/.rvm/ /usr/local/bin/rvm-shell '1.9.2' -c 'bundle install --gemfile /home/example/staging.example.com/releases/20110714180125/Gemfile --path /home/example/staging.example.com/shared/bundle --deployment --quiet --without development production'

确保在服务器上运行bundle install时已安装了bundler并且路径正确。如果未安装,则运行gem install bundler进行安装。


1
如果您已经安装了bundler,请执行以下操作:
将此行更改为 --> set :rvm_ruby_string, 'ruby-1.9.2-p180' 这对我有效。
要知道您的Ruby版本 --> rvm list

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接