简体   繁体   中英

How to set the ruby version in capistrano using rbenv

I have a Rails 4.2.0.beta2 application on my production server running on Ruby 2.1.2. I have installed Ruby 2.13 using rbenv but not yet made it global.

On my development machine I have installed Ruby 2.1.3, also using rbenv and run bundle in my application to update the gems for the new ruby version. My gems include

group :development do
  # Use Capistrano for deployment
  gem 'capistrano', '~> 3.2'
  gem 'capistrano-rails', '~> 1.1.1'
  gem 'capistrano-bundler'
  gem 'capistrano-rbenv', '~> 2.0'
  gem 'capistrano-unicorn-nginx', '~> 2.0'
  gem 'capistrano-postgresql', '~> 3.0'
end

I am using Capistrano 3.2.1 and in my deploy.rb file I have set

set :rbenv_type, :user
set :rbenv_ruby, "2.1.3"

My question is, will my Capistrano recipe switch the server ruby version and load all my new gems? I know that it normally loads new gems automatically. Specifically, will capistrano run rbenv global 2.1.3 to change the ruby version and then bundle install?

If I need to do this manually, will changing the ruby global in rbenv cause my application to blow up due to a mismatch in gems? Is the ruby version isolated between applications by rbenv?

I have tried to run this deploy recipe but it fails with

rbenv: bundle: command not found
  The `bundle' command exists in these Ruby versions:
    2.1.2

I had to

rbenv global 2.1.3
gem install bundler
rbenv rehash

Then I ran

cap production deploy

again and it was all good. I have no idea what the ruby_version directive in my deploy.rb is supposed to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM