2

I would like to understand a very basic concept in Ruby on Rails. Everytime I create a new Rails application, I used to create a gemset and then install gems to that gemset. Once my friend asked me why I do that and I failed to make him understand very clearly.

Is it because if I have 2 projects under the same Ruby version and if both need different versions of a particular gem? Suppose, both are using the default gemset, it can't install both versions of this gem to the default gemset as it would cause a conflict? Please correct me if am wrong.

Flip
  • 6,233
  • 7
  • 46
  • 75
Nimmi Mathew
  • 283
  • 2
  • 10
  • Doesn't a rails app use the gems in Gemfile regardless ? – xyious Jun 18 '16 at 07:55
  • Yes. We can specify all the gems required for the application in gemfile. Then the bundler will take care of resolving dependencies and installing gem. My doubt is regarding the gemset. What is the actual benefit of using a seperate gemset for each application? – Nimmi Mathew Jun 18 '16 at 09:48
  • gemsets were used when we had no bundler. Now they're useless. – Sergio Tulentsev Jan 30 '17 at 12:51

3 Answers3

4

Gemsets are useful to make independent rails application, where other rails application (with the same ruby version) does not share gems among each other (as it does gem bundler)

For now, using of gemsets is overhead, because:

  • gemsets decreases download gem speed
  • gemsets increases space on a hard drive
  • gem bundler handles dependencies well
  • if your gems will be corrupted, you can restore them with gem pristine --all
  • development and production environments go towards Docker with its own independent layers

Just don't use gemsets

itsnikolay
  • 17,415
  • 4
  • 65
  • 64
1

By gemset you mean RVM Gemsets right? RVM Gemset compartmentalized ruby setups, from the system and each other. This is very helpful if you have multiple Rails project for example. Each project might require different versions of same gem(s).

However, if you are using Bundler you don't need to use RVM Gemsets. Prepending any command with bundle exec will execute it in the context of the project's Gemfile.

References

Community
  • 1
  • 1
jwgoh
  • 60
  • 7
0

It's very interesting questin.

you can consider gemset is = kind of space in hard drive

I will show you full process.

if you have more then one projects with different ruby versions then we need to use rvm to avoid conflicts. so for that we need to use RVM (Ruby version manager). Steps:

1) install rvm 2) after installing rvm we need to use ruby version ex : if you have more then one ruby installed in your system then chose one of them

rvm --default use version

For example you have 2 projects with ruby 1.9.X and other project with 2.0.X

So in this situation if you are not using rvm then it may chance to get conflicts so we should create new gemset like bellow.

Ex: rvm gemset create demo rvm gemset use demo

so currently we are pointing to gemset demo

now we already install ruby but we do not have rails in this gem so we must install rails and other gems in it.

so the conclusion is that we use gemset for avoid conflict between to ruby versions.