tags:

views:

117

answers:

2

Hi everyone

If you don't install gems with sudo on a mac, by default they will be placed in a directory like

.gem/ruby/1.8/gems/

If you DO install by with sudo, my understanding is they are normally placed in the system directories, like so:

 /usr/local/lib/ruby/gems/1.8/gems/

Is there a good reason you should install gems with sudo instead, other than simply letting others share them with you? *

I'm under the impression that you'd sudo install gems because if you as user bob install the gems inside bob's directory, then a user like www-data (used by Passenger/Apache on Ubuntu Linux when serving files), to use them - is this the only reason you'd use them like this?

Or is best practice now to use something like Ruby Version Manager instead now?

I'd really appreciate hearing from some more experienced ruby developers about where you store yours and why.

+1  A: 

Running gem install with sudo means you are running the install as an admin user and as such will install it for the whole system. If you run as a normal user it will just put the gems in your home directory.

For your development machine or server, /usr/local/lib/ruby/gems/1.8/gems/ is almost certainly the right place to put gems. If you are on some kind of shared hosting or playing around with development versions of some gems, by all means, keep them in your home directory so you don't clutter up the system for other users.

I haven't heard of Ruby Version Manager before. I'll check it out.

Kenny Drobnack
A: 

AFAIK, Ruby Version Manager (RVM) is targeted more at making it simple to work with multiple Ruby versions (1.8.6, 1.8.7, 1.9.1, MRI, JRuby, etc etc) on the same machine. Since many gems include version-specific and/or compiled elements, different gem versions may be needed for use within those Ruby Versions. RVM lets you switch Ruby environment but within that environment you'd [sudo] gem install the same as always.

Mike Woodhouse