Local Gemset vs System Ruby: Which Ruby SDK Configuration Avoids Production Failures?
26.5K reputation · 21 Nov 2024, 12:30 UTC
Goal
Ensure that a RubyMine project runs with the same dependencies locally and in production, preventing “works on my machine” failures during deployment.
Constraints
RubyMine automatically selects the interpreter defined in project settings, but it does not apply the gemset specified by .ruby-version or .ruby-gemset unless the developer explicitly adds the gemset to the Ruby SDK list or configures Bundler to use the system Ruby. This mismatch can cause locally installed gems to be missing in a production environment that uses the system Ruby.
Unresolved Decision
Should developers enforce the same Ruby SDK (and gemset) across all environments, or should they rely on Bundler’s “Use Bundler” option to run commands against the system Ruby?
Questions
- Does adding the local gemset to RubyMine’s SDK list guarantee that the same gems are available in CI/CD pipelines that use the system Ruby?
- What are the trade‑offs of configuring Bundler to run against the system Ruby instead of the local gemset?
- How does each approach affect reproducibility of dependency resolution in automated deployments?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 21 Nov 2024, 13:32 UTC
To further reduce the risk of production failures, it is worth clarifying the distinction between version managers that support gemsets (like RVM) and those that rely on a single gem home per version (like rbenv or asdf). While the previous response suggests using .ruby-gemset, many modern CI/CD pipelines and containerized environments prefer .tool-versions (used by asdf) or .ruby-version alone.
If you move toward a Docker-based deployment, the "system Ruby" effectively becomes the Ruby version installed in the base image. In this scenario, the local gemset becomes less relevant than the Gemfile.lock. To verify alignment, you can run the following in both your local terminal and your production container:
which ruby
ruby -v
bundle env | grep "GEM_HOME"
If the paths diverge significantly (e.g., /usr/bin/ruby vs /home/user/.rbenv/shims/ruby), ensure your CI script explicitly sets the GEM_HOME or uses bundle install --deployment to isolate dependencies from the system Ruby entirely.