ruby-on-railscapistrano

How to deploy a Rails app with Capistrano (different Ruby version on the server)


My server has Ruby 2.6.5 and there are some Rails applications which run on this server. I would like to deploy another Rails application to this server. My local machine (development machine) has Ruby 3.1.2 which is installed by rbenv. I use Capistrano to be able to deploy.

Questions:

  1. Should I install Ruby 3.1.2 on my server to be able to deploy my new application?
  2. which version of Ruby should be set inside deploy.rb file in Capistrano for rbenv? It should be my server Ruby version or my local Ruby version?

Solution

  • You should not be developing/testing on another Ruby version as this is known to cause problems when the code is actually deployed. You want to find out about incompatibilities or inconsistencies by tanking your production server.

    This is very likely if you're not even using the same major version. Between Ruby 2.6 and 3.0 there was a lot of changes to how keyword arguments are handled and new features were introduced like argument forwarding which are breaking changes.

    You need to achieve dev/prod parity either by changing the Ruby version used in the production environment or development/testing so that they match.

    Should I install ruby 3.1.2 on my server to be able to deploy my new application?

    Yes. Ruby 2.6 was EOL:ed 31 Mar 2022.