Richlewis Richlewis - 11 months ago 37
Ruby Question

gemfile.lock and gemset Ruby applications

Looking for some clarification on the benefits of using a gemset in my application and the difference between these two scenarios

1) Specify the ruby version in my

and have no gemset

2) create a

So in the first scenario I would run bundle and all of my gems dependencies and versions would be written to the Gemfile.lock

In the second scenario the same would happen but a gemset would also be created.
Each time i cd into the project with the gemset, it uses that gemset.

My scenario is I have multiple ruby applications and I dont want to have any gem incompatibility issues and also keep a consistent approach

So firstly am i missing some fundamentals here and secondly what value would the gemset give me that is not already covered by the Gemfile.lock



So a few things.

Firstly the .ruby_version is used to specify which version of ruby to use for the folder you are within. This is useful if you are running multiple versions of ruby and for ensuring the application runs that version of ruby. If there is no .ruby-version then the global version of ruby will be used.

When you call gem install or bundler it will install the gems according the version of ruby that it is called from. So if your global version of ruby is ruby-2.0 and you local ruby in .ruby_version is ruby-2.3.0 and you call bundle install from your local ruby, it will install gems against ruby-2.3.0.

This .ruby-version is unrelated to the .ruby-gemset and can be used with or without it.

Secondly. A .ruby-gemset file specifies the gemset that an application should use, much like a Gemfile.lock file that bundler creates. If you are starting your application with bundle exec the application will use the bundled gems installed. If you just start your application, the global gems will be used and scoped if you have a .ruby-gemset file.

Some folks like myself love bundler, others don't. You do not need to use bundler, but like other package managers in other applications it does make life easier in certain scenarios.

See this old example about specifying ruby versions for your gems in your GemFile (