1

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?

CafeHey
  • 5,699
  • 19
  • 82
  • 145

1 Answers1

1

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

Casper
  • 33,403
  • 4
  • 84
  • 79
  • That's great thank you so much! Can I ask how you tracked it down please, in the pursuit of teaching, I had a good google of the issue and couldn't find this solution. – CafeHey May 29 '22 at 08:25
  • 2
    Thank U. My first task was to understand what puma-dev is. I never heard of it, and it took quite a while to figure out what it actually does. I made a note of it as some sort of Rails/Rack launcher front-end. Next task was to figure out HOW it does what it does, as it seemed like a slightly magic tool that "just works", but not really explained how. I think I googled puma-dev and bundler, and came upon an issue that showed exactly the source code line that launches everything in puma-dev. This was tremendous help, and direct answer to the "how" question. It runs `bundle exec` using `bash -c`. – Casper May 29 '22 at 09:33
  • 2
    At this point I suspected your issue as some sort of failure to load the environment based on a different shell setup, because of their use of Bash. It turns out this is partially true, but perhaps not the full explanation. I find out you could use these dot files to adjust the env. Interesting. Progress. Finally I think I just put chruby into their issue tracker for the sake of seeing if such a search would producce any results, and this issue came up, putting the final puzzle pieces in place. A bit of luck which sped up the solution. – Casper May 29 '22 at 09:41
  • 1
    So lesson for myself also: try the issue tracker first before anything else :) – Casper May 29 '22 at 09:43