简体   繁体   中英

In Rails, how do you have multiple versions of puma-dev running on different versions of Ruby via ruby-install?

I have many different Rails apps using puma-dev .

I have started a new Rails app using Ruby 3+ which works great on localhost, however when I visit the site via puma-dev I get an error. This is because I think puma-dev is using the wrong version of Ruby to start the app.

The puma dev logs show this error:

! Unable to load application: Bundler::RubyVersionMismatch: Your Ruby version is 2.6.6, but your Gemfile specified 3.1.2
/Users/abc/.gem/ruby/2.6.6/gems/bundler-2.2.28/lib/bundler/definition.rb:441:in `validate_ruby!': Your Ruby version is 2.6.6, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMismatch)

I'm using ruby-install and chruby to select differernt Rubies.

How do I go about making puma-dev use the versions of ruby installed via ruby-install so that all my different apps can use differnt versions of Ruby?

It seems puma-dev is not fully compatible with chruby in all situations. But this can be fixed by creating a .pumaenv file in your Rails project folder:

# Load chruby
source /usr/local/share/chruby/chruby.sh

# Change to your desired Ruby version
chruby ruby-3.1.2 

Please adjust according to where your chruby.sh file is installed on your system.

If you want to make the setup compatible with .ruby-version files, you could do this instead:

source /usr/local/share/chruby/chruby.sh
chruby $(cat .ruby-version)

For further discussion on this topic see this puma-dev issue:
https://github.com/puma/puma-dev/issues/53

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