Search code examples
ruby-on-railsrubycapistranorbenv

capistrano-rbenv: Why is it ignoring rbenv_ruby?


OK. So I'm trying to deploy a new version of an app using capistrano. I'm using rbenv, and have 1.8.7 installed (for the old app) and 2.4.1 installed (for the new app). My Capfile includes:

require "capistrano/rbenv"

and my deploy.rb:

set :rbenv_type, :user
set :rbenv_ruby, "2.4.1"

namespace :deploy do
  desc "Show ruby version"
  task :ruby_version do
    on roles(:all) do |h|
      execute "ruby --version"
      execute "rbenv versions"
    end
  end
end

Running cap production deploy:ruby_version yields:

00:00 deploy:ruby_version
      01 ruby --version
      01 ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux]
    ✔ 01 deploy@example.com 0.390s
      02 rbenv versions
      02   system
      02 * 1.8.7-p370 (set by /home/deploy/.rbenv/version)
      02   2.4.1
    ✔ 02 deploy@example.com 0.371s

I've tried a variety of things — set :default_env, {"RBENV_VERSION => "2.4.1"}, removing /home/deploy/.rbenv/version (which makes me use system ruby) — but nothing seems to let rbenv_ruby override the other setting.

Setting rbenv_ruby to a nonexistent version throws an error, so it appears to be doing something.

I'm going nuts. What am I doing wrong?


Solution

  • Okay. Instead of

    execute "rbenv versions"
    

    I wanted:

    execute :rbenv, "versions"
    

    the two look real similar but are not at all the same:

    http://capistranorb.com/documentation/getting-started/tasks/

    tl;dr: execute(:bundle, :install) and execute('bundle install') don’t behave identically!

    siiiiiiiiiiiiiiigh