简体   繁体   中英

Different ruby versions by environment in a Gemfile for rails application

I'm currently using capistrano 3 to deploy my rails 4 application across several environments. I want to try and move to ruby 2.1.2 in development (I'm running 2.0.0 in stage / prod). Is it possible to somehow specify this in a single Gemfile assuming I am using rbenv?

I've tried to following in my Gemfile but to no avail:

# Gemfile
group :development do
  ruby '2.1.2'
end

group :staging, :production do
  ruby '2.0.0'
end

When cap deploy runs on development it aborts due to the perceived version mismatch.

Your Ruby version is 2.1.2, but your Gemfile specified 2.0.0

Here is the command it is trying to run.

cd /home/rails/releases/20140701151045 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 RAILS_ENV=development RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )

Ideas are much appreciated. Thanks!


Update After input from @toolz and reviewing the bundler code, this just isn't possible (or a good idea). There are a couple of options:

  1. Remove the "ruby" entry from the Gemfile (anything goes)
  2. Create separate Gemfiles
  3. Create a separate branch for the move to the new Ruby version

I'm going with option #3 and it will solve my problem and seems to be the best practice.

I got it working by doing

Gemfile

if ENV["RAILS_ENV"] == "development"
  ruby '2.0.0'
elsif ENV["RAILS_ENV"] == "production"
  ruby '2.1.0'
end

then assuming you're using rvm you'll have to create a capistrano task to do

rvm use 2.1.0

on production

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