简体   繁体   中英

Specify different Ruby versions (e.g. 1.9.3 vs 2.1) in Gemfile for Windows and Linux/OS X?

I'm on a Ruby on Rails project where we have Windows and Linux computers. The project uses Ruby 2.1, but as a windows dev I need to use a lower version of Ruby like ruby 1.9.3 or Ruby 2.0 in order to smoothly do local dev work.

So to implement custom Ruby versions for my Rails project based on platform automatically, I tried to modify the Gemfile to segregate different Gems and Ruby Versions for each platform:

platforms :ruby do # linux & Mac only
  ruby '2.1.0' #doesn't work, still tries to load ruby 1.9.3
  gem 'puma', '~> 2.7.1' #works
end

platforms :mswin do #Windows only
  ruby '1.9.3' #doesn't work, overrides Linux/mac users to Ruby 1.9.3 rather than 2.1
  gem 'thin' # works
end

platforms :ruby or platforms :mswin apparently only works for designating Gems, and doesn't work for specifying Ruby versions. How do I set up my local windows dev environment so that I can work on a lower/different Ruby version automatically within the same Gemfile without affecting my co-workers?

Note:

.rubyversion reads 2.1.0 While I could .gitignore this file to specify for each environment, Heroku requires us to specify a Ruby version within the Gemfile--so we need some way to resolve this at the Gemfile level.

Gemfile是用Ruby实现的DSL,因此您可以在这里调用Ruby代码:

ruby RUBY_PLATFROM =~ /win/ ? '1.9.2' : '2.1.0'

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