views:

490

answers:

2

I have a machine that is running Ubuntu Hardy, which provides its own RubyGems package. Unfortunately that version of RubyGems (1.1.1) is too old to do anything useful with, so I decided to manually update RubyGems to the current version (1.3.6). That part went smoothly, and if I do gem -v, I get 1.3.6 which is expected. The problem is when I try to do: sudo gem install rack, it returns this error:

ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /home/username/.gem

Usually when I install gems as root, it knows to install it into /usr/lib/ruby/gems, so why is it checking my home directory at all? Another quirk is when I do gem install rack (not as root), it says:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.

which is where I want it to go. I've already tried clearing source_caches, trying different versions of RubyGems (1.3.5), forcing installation into /usr/lib with -i to no avail. Any ideas on why RubyGems is so insistent on checking my /home directory when installing as root?

+1  A: 

Sounds like it could be a path issue coupled with having multiple versions installed.

Any difference in output between:

sudo gem env

and

gem env
SundayEdition
No difference in the two, though in the GEM PATHS section: `/usr/lib/ruby/gems/1.8` and `/home/username/.gem/ruby/1.8`. Shouldn't that not be there by default with sudo?
Kenny Peng
They're the same on my system, but only after I went through and 'scrubbed' everything after recompiling 1.9. Things I checked:1. Deleted the un-used gem command (had one in /usr/bin and /usr/local/bin2. Checked my ~/.gemrc file and cleaned the path up to point to my gem path in /usr/local/lib. Used my ~/.gem folder as a backup3. Matched my GEM_HOME and GEM_PATH environment variables up (in .profile/.bash_profile/.bashrc) with the .gemrc file4. Checked permissions on the gem folders5. You might also check to see if you have anything in /etc/gemrc
SundayEdition
So I went through these suggestions and they all seem to check out: 1) only one gem executable in /usr/bin, 2) no .gemrc, 3) I never set these variables in my .profile, 4) gem folders had permissions for root, which sudo should be fine with, 5) no /etc/gemrc. The only other hitch is maybe the fact that my home directory lives on AFS screws things up?
Kenny Peng
Check this: http://stackoverflow.com/questions/257616/sudo-changes-path-whyMaybe the old version of gem wasn't installed in /usr/bin or /usr/local/bin, and sudo is picking up a different PATH variable (to gem) or a GEM_PATH (which points to your /home/username path) from somewhere?You might check /etc/environment as well and try to find out where sudo is picking up its environment variables from (maybe a root .profile?).
SundayEdition
I believe the problem was caused by having my home directory on AFS. RubyGems seems to write metadata into your `.gem` directory (`~/.gem/specs`) regardless of whether you are running as root via sudo. But running as root means that you credentials don't carry over and you can't do anything to AFS. I ended up using `sudo su` and installing things as root proper. It did install into `/usr/lib/ruby/gems` and wrote some metadata into `~/.gem/specs`. Thanks for all the help, I was able to narrow down the scope of the problem a lot.
Kenny Peng
A: 

Try running:

gem environment

and checking the values for the GEM PATH. More info at http://docs.rubygems.org/read/chapter/10#page31

nutcracker