How to reduce duplicate gems with RVM and Bundler?

154 Views Asked by At

I work at a company where I develop on over 10 different ruby and rails apps. Between these ten apps, I have 3 ruby versions and 7 gemsets (total). There are certain utility gems (like pry, colored, git-up, hookup, etc.), which I would like to be able to install once (per ruby — if necessary) and have access to across gemsets within the same ruby versions.

I tried installing these gems into the 'global' gemset for each ruby version, however, once I cd into a project and the gemset changes (same ruby version though), I no longer have access to the gem's executable. I have to reinstall the gem in the specific gemset.

I just get the feeling that I am missing something as I have so many duplicate gems installed on my system. What are the best practices around this desired behavior? Can anyone point me in the right direction?

Thank you.

1

There are 1 best solutions below

1
On BEST ANSWER

If you wanna install a gem per ruby, you need to do a gem install pry for instance. That will install the gem on the ruby level. After that you can require that in your Rails app, for instance on the boot.rb file. I am not sure how rvm deals with gemsets. If what they do is change the entire folder reference of the gem command, then you wont be able to do that. I would need to install those gems for every gemset, which is a PITA.

On my workflow, I dont need gemsets, as I have bundler. So I use rbenv to install and change ruby versions, and let bundler deals with gems for a project. Like so, I can install a gem, globally per ruby, and it works.