views:

1790

answers:

3

running 'sudo gem list --local' and 'gem list --local' gives me differing results, my gem path is set to my home folder and only contain the gems from 'gem list --local'.

So it's probably not good to have gems installed in different directories on my computer, should I have the gem path set differently? and should I always use sudo when installing something?

my ~/.profile export PATH=/opt/local/bin:/opt/local/sbin:$PATH export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

bash_profile is empty

A: 

You should usually use sudo. Only reason not to is on a shared host where you want to install a gem and don't have sudo rights. Then leaving it off installs the gem in a location for your user only.

But if you can use sudo, do.

Squeegy
A: 

Generally you'll want to put gems in a single location on your system, but there's no real reason for that other than maintaining your sanity when something requires you to dig through source code.

Personally I chose the system-wide location because I have teammates ssh-ing into my machine on occasion and I have rails applications that run as a different user.

So what I do is simply add a line like alias gem='sudo gem' into my .profile... Problem solved.

thenduks
+12  A: 

Contrary to all the other posts I suggest NOT using sudo when installing gems.

Instead I recommend you install rvm (http://rvm.beginrescueend.com/) and start a happy life with portable gem homes and different version of ruby all living under one roof.

For the uninitiated:

RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments and sets of gems.

Edit: The reason why installing gems with sudo is worse than just gem install is because it installs the gems for ALL USERS as root. This might be fine if you're the only person using the machine, but if you're not it can cause weirdness.

If you decide you want to blow away all your gems and start again it's much easier, and safer, to do so as a non-root user.

If you decide you want to use RVM then using sudo will cause all kinds of weirdness because each ruby version you install through RVM has it's own GEM_HOME.

Also, it's nice if you can make your development environment as close to your production environment as possible, and in production you'll most likely install gems as a non-root user.

jonnii
+1 for the rvm suggest, but -1 for the confusing condemnation of the alternate possibility of just using sudo
floyd
It's really not that confusing. http://rvm.beginrescueend.com/gems/
jonnii
@floyd, updated the post with more reasons to not use sudo.
jonnii
Ok, but all your reasons boil down to "because RVM is so great" not because using sudo is especially harmful. The only time you wouldn't want to is in the specific situation that you're on a shared computer. If you want to recommend rvm just do that. No need to resort to FUDD.
floyd
I try not spread FUD, and I tried to give non-RVM reasons, I apologise if it seems that way.
jonnii