部署 使用 bundler/capistrano 后的 gem 路径问题

suupic · June 29, 2012 · Last by suupic replied at June 29, 2012 · 7636 hits

在 capstrano 中,使用了

require "bundler/capistrano"

在 bundle 时,capstrano 自动将项目依赖的 gem 安装在 shared/bundle 目录里,这对隔离项目很有好处。capstrano 的各项任务也运行正常。

但是我遇到了另外一个问题: 由于所有的 gem 都放在 shared/bundle 里,包括 rails 也在里面 然后我又使用了 rvm,由于 gem 都 bundle 到 shared 里,rvm 的 gem list 基本是空的 这时,手动执行 rails、unicorn 等命令,依然会去 rvm 的目录里查找,当然是找不到的

 /opt/deploy/proj/shared/bundle/ruby/1.9.1/bin/rails --help
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (>= 0) amongst [bundler-1.1.4, kgio-2.7.4, rack-1.4.1, raindrops-0.10.0, rake-0.9.2.2, rubygems-bundler-1.0.3, rvm-1.11.3.4, unicorn-4.3.1] (Gem::LoadError)
        from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
        from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem'
        from /opt/deploy/zimei/shared/bundle/ruby/1.9.1/bin/rails:22:in `<main>'

由此,问题是: 怎样才能正确使用 shared/bundle 里的 gem 环境(其实是不想在 rvm 里再装一套 rails)

用 bundle exec rails ...

You need to Sign in before reply, if you don't have an account, please Sign up first.