Managing Required Gems on Rails Projects
27 comments Latest by Dental Implants Tue, 09 Mar 2010 18:39:48 GMT
We’re starting a new project and I’m finding myself adding things to the code base that we’ve done in the past… hence the last few posts. As we’re doing this, I’d like to highlight some of the little things that we do on each project to maintain some consistency and in that process reach out to the community for alternative approaches.
I’m intrigued by the vendor everything concept, but we haven’t yet adopted this on any of our projects (yet).
What we have been doing is to maintain a REQUIRED_GEMS file in the root directory of our Rails application.
For example:
$ cat REQUIRED_GEMS
actionmailer
actionpack
actionwebservice
activerecord
activesupport
cgi_multipart_eof_fix
daemons
fastercsv
fastthread
feedtools
gem_plugin
image_science
mongrel
mongrel_cluster
mysql
rails
rake
RedCloth
Ruby-MemCache
soap4r
uuidtools
Everybody on the team (designers/developers) knows to look here to make sure they have everything installed when beginning to work on the application.
This has worked fairly well from project to project but since we’re starting a new project, I’m curious if anybody has some better ways to approach this. Should we look more seriously at the vendor everything approach or are there any alternative approaches?
Enjoying the content? Be sure to subscribe to my RSS feed.






We’ve been using the gemtracker plugin, which allows you to define the required gems and versions in config/gems.yml, and then raises an error when the server starts up if a dependency is missing. Also provides rake gems:install to install all the dependencies.
It’s worked out really well and is one of the reasons that we haven’t vendor’d everything.
GemInstaller looks pretty robust.
Don’t forget you can have cap require certain gems when deploying too.
Use geminstaller. We’ve been using it for our project (as has every project at the pivotal office) for the last several months. It’s awesome.
I like the FrozenGemsGenerator
I like the FrozenGemsGenerator
We’ve had a lot of luck with vendor everything. We unpack gems (with version numbers intact in the directory name) into vendor/gems and have a one-liner in environment.rb that adds each gem directory to the load path.
It’s great to be able to know not only which gem we’re using but which specific version.
It’s nice to have your team begging to work on your application!
@raymond: hah! nice catch. :-)
Another vote for GemInstaller. As compared to others, it also solves the platform specific gems problem, as well as deals with ensuring the gems you specified are what are actually on your app’s load path, even if you have multiple versions of the same gem installed. Here’s some more info I wrote up about it.
Thanks for the link brandon :)
+1 for GemInstaller. Also, I put a dependencies.rb file in config/initializers to require other non-gem files.
We love cap deploy:check
GemInstaller does look like a good solution. On that note, here is an interesting discussion on Rails Trac regarding a potential addition to RoR core http://dev.rubyonrails.org/ticket/11167
I don’t see gem versions listed, though. You seem to be assuming that there is backwards-compatibility.
Have you ever looked at http://rubyforge.org/projects/plugems Plugems? It’s what we use at Revolution Health.
For my open source Rails app, called Kete (Maori word for basket, http://kete.net.nz) I built code for both gems and other required supporting software.
If you want something that will report when other required software besides gems is uninstalled it might have some good example code:
http://svn.kete.net.nz/projects/kete/trunk/config/required_software.yml http://svn.kete.net.nz/projects/kete/trunk/lib/required_software.rb http://svn.kete.net.nz/projects/kete/trunk/config/initializers/check_for_missing_software.rb
If a Kete app is started and MISSING_SOFTWARE is not blank it will give a helpful message with what needs to be installed.
Cheers, Walter
For my open source Rails app, called Kete (Maori word for basket, http://kete.net.nz) I built code for both gems and other required supporting software.
If you want something that will report when other required software besides gems is uninstalled it might have some good example code:
http://svn.kete.net.nz/projects/kete/trunk/config/required_software.yml http://svn.kete.net.nz/projects/kete/trunk/lib/required_software.rb http://svn.kete.net.nz/projects/kete/trunk/config/initializers/check_for_missing_software.rb
If a Kete app is started and MISSING_SOFTWARE is not blank it will give a helpful message with what needs to be installed.
Cheers, Walter
For my open source Rails app, called Kete (Maori word for basket, http://kete.net.nz) I built code for both gems and other required supporting software.
If you want something that will report when other required software besides gems is uninstalled it might have some good example code:
http://svn.kete.net.nz/projects/kete/trunk/config/required_software.yml http://svn.kete.net.nz/projects/kete/trunk/lib/required_software.rb http://svn.kete.net.nz/projects/kete/trunk/config/initializers/check_for_missing_software.rb
If a Kete app is started and MISSING_SOFTWARE is not blank it will give a helpful message with what needs to be installed.
Cheers, Walter
Hi,
Thanks for the GemInstaller propz. Full disclosure – I currently have broken tests against the new 1.1.0 RubyGems release (http://ci.thewoolleyweb.com/), which I’m working on. Strangely, I was green against trunk the day before the release, so I dunno WTF. I hope to have this fixed soon, limited only by my programming skills and ability to stay awake hacking after putting the kid to bed. Contributions welcome ;)
@lee,
A better “reimagined” approach just made it into trunk here:
http://dev.rubyonrails.org/ticket/11444
This finally looks like the right solution. Any gem pre-loaded on the load path (via GemInstaller hook in preinitializer, for example) will be picked up, and there can be a rails_init hook which will make the loaded gem be initialized like a plugin.
I haven’t tried this on any plugins yet, but I’m really excited about it. It looks like the best solution overall when used with GemInstaller – explicit auto-installed and auto-loaded dependencies as gems, installed/compiled for the proper current platform, controlled via a config file, which can also act as rails plugins.
@lee,
A better “reimagined” approach just made it into trunk here:
http://dev.rubyonrails.org/ticket/11444
This finally looks like the right solution. Any gem pre-loaded on the load path (via GemInstaller hook in preinitializer, for example) will be picked up, and there can be a rails_init hook which will make the loaded gem be initialized like a plugin.
I haven’t tried this on any plugins yet, but I’m really excited about it. It looks like the best solution overall when used with GemInstaller – explicit auto-installed and auto-loaded dependencies as gems, installed/compiled for the proper current platform, controlled via a config file, which can also act as rails plugins.
You can manage required gems in EDGE now: http://dev.rubyonrails.org/changeset/9140/trunk/railties/CHANGELOG
Rake tasks are also provided to installed all the required gems.
Great detailed information, I ll be visiting you more frequently, this is very interesting information
This post is really well written as it has provided all detailed facts and information about the topic. This post speaks credibility and authenticity and exposes real caliber of the writer. Fantastic job!
Hey – great website, just looking around some blogs, seems a really nice platform you are using. I’m currently using Wordpress for a few of my blogs but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?
I finally found one post which is informative and which has provided genuine information for the readers. I really liked the way writer has thrown some light on unhidden facts. Great job in deed
I have seen many posts similar to this one on internet but all other have filler content and are not up-to-the mark. This post especially made me to post my comments as its credible, it’s well written and above all it is interactive in nature. Well done!